Application::redirect
別のURLにリダイレクトして、処理を終了します
説明
public void Application::redirect( string $url )
Locationヘッダー(HTTP 302)を送り、Fegg\Http\Haltを投げてレスポンスを終了します(レスポンスの終了を参照)。redirect()の後のコードは実行されません。
http://かhttps://で始まるURLは、そのまま使います。- それ以外のURLは、サイト内のパスとして扱います。先頭の
/、末尾の/(拡張子がない場合。URLを参照)、ベースパスを付け、スキームとホストなしで送ります。そのため、ページのスキームはそのまま保たれます(セキュリティを参照)。
引数
| 名前 | データ型 | デフォルト | 備考 |
|---|---|---|---|
| $url | string | 絶対URL、またはサイト内のパス |
例
Controller
// Location: /news/
$this->redirect('/news/');
// Location: /news/ (slashes added)
$this->redirect('news');
// Location: /contact/result.html
$this->redirect('/contact/result.html');
// Location: /sub/news/ (site installed in /sub/)
$this->redirect('/news/');
// Location: https://www.example.org/
$this->redirect('https://www.example.org/');
リクエストから受け取ったURL(たとえば$this->in('return_to'))は、チェックせずに渡さないでください。サイトがオープンリダイレクトになってしまいます。