3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHPのController::redirectがhttpに飛ばすのでbeforeRedirectでhttpsに飛ぶようにしてみた

Posted at

先に結果
基底のController等があればそこに追加で

public function beforeRedirect(Event $event, $url, Response $response)
{
    // httpsにリダイレクトするように設定
    $response = $response->withLocation('https://' . $_SERVER["HTTP_HOST"] . Router::url($url));
    return $response;
}

Controller.beforeRedirectのオーバーライドして
Controller::redirectの動作に割り込みをかけます。
元のメソッドはreturn null;
してるだけなので気にせず書き換えます。

$this->redirect(['controller' => 'Login', 'action' => 'index']);

こんな感じで書くと元々httpにリダイレクトされてましたが
それをhttpsに書き換えています。

3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?