How to force Laravel Project to use HTTPS for all routes?

前端 未结 10 498
攒了一身酷
攒了一身酷 2020-12-13 03:33

I am working on a project that requires a secure connection.

I can set the route, uri, asset to use \'https\' via:

Route::get(\'order/details/{id}\',         


        
相关标签:
10条回答
  • 2020-12-13 04:27

    You can set 'url' => 'https://youDomain.com' in config/app.php or you could use a middleware class Laravel 5 - redirect to HTTPS.

    0 讨论(0)
  • 2020-12-13 04:29

    Place this in the AppServiceProvider in the boot() method

    if($this->app->environment('production')) {
        \URL::forceScheme('https');
    }
    
    0 讨论(0)
  • 2020-12-13 04:30

    Add this to your .htaccess code

    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
    

    Replace www.yourdomain.com with your domain name. This will force all the urls of your domain to use https. Make sure you have https certificate installed and configured on your domain. If you do not see https in green as secure, press f12 on chrome and fix all the mixed errors in the console tab.

    Hope this helps!

    0 讨论(0)
  • 2020-12-13 04:35

    try this - it will work in RouteServiceProvider file

        $url = \Request::url();
        $check = strstr($url,"http://");
        if($check)
        {
           $newUrl = str_replace("http","https",$url);
           header("Location:".$newUrl);
    
        }
    
    0 讨论(0)
提交回复
热议问题