I have a rather old website that I’ve fed up refactoring so I’m rebuilding.
The old URLs don’t have any naming consistency for me to create some sort of rule so, is it possible to have some sort of router/controller that forwards ($this->_forward()) the old URLs to their new location?
For instance when I’m calling http://www.example.com/this-is-a-url-with-a-random-name.php it will forward to http://www.example.com/url/random-name …
Maybe this match could exist in an array so the key would be the old URL and the value would be the new location?
Or am I just trying to re-invent the wheel and I should just stick with the good ol’ .htaccess rules with 301 redirects?
(I hope all this makes sense?)
Cheers,
Angel
I’ll start off by recommending using your apache config to place the rewrites if possible. It’s much faster than both using .htaccess and your Zend Framework application.
I’ll also say that you do want to use 301 redirects as they are the best for search engines when your content has been moved permanently.
If you want to use your Zend Framework application to do this and if you have a bunch of URLs that may have different structures, the best place is in the default error controller as a ‘last ditch effort’. The reason for this is that if you have an url
/myoldurlthat doesn’t exist now (but is on your redirect list) and you implement it in the future as it’s own controller/module – your controller will automatically take over.Inside
errorAction()there is a switch that decides if your error is a 404 or a 500.Inside the 404 block you can add code to do a redirect. This is not complete code, look it over and insert missing pieces of data as needed.