How to implement HTTPS in laravel 5.4

2019-07-20 22:10发布

I have a shared hosting with OVH(France) and i have the "Let's Encrypt" certificate for my domain.

however, i looked everywhere for redirecting all requests from HTTP to HTTPS in laravel 5.4

i have found a solution with ".htacces redirecting" but i often have "TOO_MANY_REDIRECT" errors on browsers specially Google Chrome.

Anyone have an idea for redirecting all PS : i don't have "sudo" rights on my shared hosting server (just user access with ssh)

Regards,

3条回答
倾城 Initia
2楼-- · 2019-07-20 22:24

You can set 'url' => env('APP_URL', 'https://localhost'), in config/app.php. That should do the trick.

查看更多
冷血范
3楼-- · 2019-07-20 22:28

in addition to @Troyer answer, i added the code below to my .htacces

RewriteEngine on

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]

and now all request to HTTP are redirected to HTTPS without the "TOO_MANY_REDIRECT" errors thank you very much guys for your answers best regards,

查看更多
该账号已被封号
4楼-- · 2019-07-20 22:33

Without modify the .htaccess file, you can force the https protocol in your Laravel application adding:

function boot() {
     URL::forceScheme('https');
     ... your code
}

In your AppServiceProvider.php.

查看更多
登录 后发表回答