There are yii 1.1. After editing the aliases of the pages in the database, it became necessary to make 301 redirects from the old URLs to the new ones. When in the CApplicationComponent class, in the init() method, I put a simple test for the test on $_SERVER['REQUEST_URI'] with a subsequent redirect to the correct URL - immediately sends to 404 pages. Any thoughts on how to do it correctly?

  • more specifics on how requests are processed, what else is done, well, etc. - Artem
  • Oh I do not even know what more information to give. I make changes to the site on wii, but I can not configure the redirect. The problem is that on the pages with aliases in the database, the crutch redirect works, but as soon as it comes to a nonexistent alias, page 404 is loaded immediately with the same URL in the address bar. - tekken
  • Well, for a start, a piece of code, how a redirect happens. As if there are no those who can imagine what is written there. - Artem

1 answer 1

If only aliases have changed, then redirect in the controller itself. Which is responsible for processing requests for these pages. That is, before any actions, check if there is a page in the database that has an old alias that matches the requested one. If there is - knowing its new alias - do a redirect. When requesting pages with a new alias, there will be no redirect, because there is no page with that name.

If the paths have changed in the root, then this is easily done at the urlManager level + new controller specially made for redirects. If you give examples of addresses of old and new pages sign for more with an example.