LoginSignup
0
0

More than 1 year has passed since last update.

php: いろいろなリダイレクト

Posted at

リダイレクトしたいURL
https://sample.domain/xxx

https://xxx.jp

★PHPでかく場合

  /**
     * @Route("/xxx", name="xxx")
     */
    public function index()
    {
        header('Location: https://xxx.jp', true, 301);
        exit;
    }

★Symfonyで書く場合

    /**
     * @Route("/xxx", name="xxx")
     */
    public function index()
    {
        return $this->redirect('https://xxx.jp', 301);
    }

★.htaccess でやる場合

(Rewrite Engine on の下に追記する)
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule ^xxx$ http://xxx.jp/? [R=301,L]
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule ^xxx/sub$ http://xxx.jp/sub? [R=301,L]

★AWSでやる場合

image.png

個人的には、AWS管理画面からリダイレクトさせた方が安全そう
status:301(引っ越しました)を返せるリダイレクトが SEO的にも好ましいです。

0
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
0
0