How to redirect a url using query string in symfony2?

I am rewriting an old project using Symfony2, so I can try the framework. I have URLs that will take the form:

/profile/{id}

in that symfony2 does this. However, the same page was originally found:

/profile.php?id=12345

So, if someone has an old url, I would redirect those links. The problem is that I do not know how to catch routes of this kind. I tried

/profile.php?id={id}

but that didn't seem to work. How to configure this route?

Follow-up observation: I do not want to do catch-all (because it is not intuitive for me, so I am afraid of future errors), and I would prefer not to do this through htaccess for the same reason. I think the best option is to match "/profile.php" and then in the controller, check that "id" exists in the query string and is redirected accordingly. If it is not, I will go to 404.

+5
source share
1 answer

Here I see two options:

  • You map your old schema (/profile.php?id=54321) to the new one (/ profile / 54321) using mod_rewrite (if using Apache).

  • Symfony. , , , :


whatever:
  pattern: /{whatever}
  defaults: { _controller: CoreBundle:Default:whatever }
  requirements:
    whatever: .+

(2) , - (, getQueryString()), b/c. , - : xyz .

+3

All Articles