php: 各种重定向

希望重定向的网址为:
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管理界面进行重定向,这样更安全。通过返回301状态码(已永久移动),实现重定向对于SEO来说也是理想的。