LoginSignup
3
1

More than 5 years have passed since last update.

Symfonyで特定パス以下を全部リダイレクトする

Last updated at Posted at 2018-10-19

TL;DR

もう使わなくなったURLとかで、特定パス以下を全部リダイレクトしたいというケースってありますよね。

NginxやApacheでリダイレクトする方法もあると思いますが、アプリでやりたい場合もあると思います。

そういう場合の方法

Symfony Routingの書き方

この機能を利用

use Symfony\Component\Routing\Annotation\Route;

class DefaultController
{
    /**
     * @Route("/old-url-path/{any}", requirements={"any"=".+"})
     */
    public function someAction()
    {
        return $this->redirectToRoute('top_page'):
    }
}

こうすることで {any} に スラッシュ / が含まれていてもトップページへリダイレクトすることができます。

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