LoginSignup
1
0

More than 1 year has passed since last update.

[Laravel] HTTPS での接続を強制する

Posted at

Laravel を使ったサイトをさっき検証環境、本番環境にリリースしたらHTTPとHTTPSが混在してるよ!!という事でうまく動きませんでした。

{!! Form::open(array('url' => '/login', 'role' => 'form', 'name' => 'loginForm', 'id' => 'loginForm', 'class' => 'login')) !!}

こういう記述があるとHTTPSページ内にあるフォームのPOST先がHTTPになってエラーになったりします。

こちらの解決方法を以下に記します。

結論

web.php に以下を記述します。

if (App::environment('production') || App::environment('staging')) {
    URL::forceScheme('https');
}

App::environment('production')は本番環境の.envファイルにAPP_ENV=productionと記述されている前提で動きます。

App::environment('staging')は検証環境の.envファイルにAPP_ENV=stagingと記述されている前提で動きます。

これで全てのリクエストはHTTPSに統一されます。

以上

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0