simpsons3
simpsons3

Reputation: 991

url() return http while sever running on https

I'm create a web using laravel on a https website example: https://examples.com. And I have a blade view which has a form with action to another page https://examples.com/next I used this in my blade file: <form action="{{url("next")}}" method="POST" id="page">.

But when I test on browser, it show an warning like: Mixed Content: The page at 'https://examples.com' was loaded over a secure connection, but contains a form that targets an insecure endpoint 'http://examples.com/next'. This endpoint should be made available over a secure connection.

When I inspect <form>, it show <form action="http://examples.com/next" method="POST" id="page">

Anyone has idea about this? Thanks

Upvotes: 2

Views: 3944

Answers (1)

N69S
N69S

Reputation: 17216

url() helper in laravel uses automatically http/https depending on the protocol of the request. If the page is https://examples.com it should generate https links.

If there is a proxy in place that switchs protocol, that error might happen. In that case you have two choices.

A local solution

<form action="{{secure_url("next")}}" method="POST" id="page">

a global solution

//in app\Providers\AppServiceProvider.php 
class AppServiceProvider extends ServiceProvider
{
    public function boot(UrlGenerator $url)
    {
        if (env('APP_ENV') !== 'local') { //so you can work on it locally
            $url->forceScheme('https');
        }
    }
    //...
}

Upvotes: 7

Related Questions