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

前端 未结 10 535
攒了一身酷
攒了一身酷 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:23

    Here are several ways. Choose most convenient.

    1. Configure your web server to redirect all non-secure requests to https. Example of a nginx config:

      server {
          listen 80 default_server;
          listen [::]:80 default_server;
          server_name example.com www.example.com;
          return 301 https://example.com$request_uri;
      }
      
    2. Set your environment variable APP_URL using https:

      APP_URL=https://example.com
      
    3. Use helper secure_url() (Laravel5.6)

    4. Add following string to AppServiceProvider::boot() method (for version 5.4+):

      \Illuminate\Support\Facades\URL::forceScheme('https');
      

    Update:

    1. Implicitly setting scheme for route group (Laravel5.6):

      Route::group(['scheme' => 'https'], function () {
          // Route::get(...)->name(...);
      });
      

提交回复
热议问题