How to implement HTTPS in laravel 5.4

前端 未结 4 2011
孤城傲影
孤城傲影 2021-01-23 03:28

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

相关标签:
4条回答
  • 2021-01-23 04:08

    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,

    0 讨论(0)
  • 2021-01-23 04:25

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

    0 讨论(0)
  • 2021-01-23 04:29

    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.

    0 讨论(0)
  • 2021-01-23 04:34

    If you'd like to force HTTPS over all URLs of your app without having to change your Apache or Nginx configuration, you need to update your AppServiceProvider as followed:

    <?php
    
    namespace App\Providers;
    
    use Illuminate\Support\ServiceProvider;
    
    class AppServiceProvider extends ServiceProvider
    {
        /**
         * Register any application services.
         *
         * @return void
         */
        public function register()
        {
            if (env('APP_ENV') === 'production') {
                $this->app['url']->forceScheme('https');
            }
        }
    }
    

    PS: you can remove the condition if you have SSL enabled on your local development environment.

    0 讨论(0)
提交回复
热议问题