One of our clients have recently moved over to Magento which has changed all the previous URLs
The previous URLs were like
and some with cpath, like
Now I need to redirect all these URLs to their respective new ones, like
So how do I go about setting these up?
Previously I had worked on setting up redirects matching all URLs with query strings and redirecting them to a specific page but have never worked on setting up page by page redirects with query strings
You could add hundreds of rules to your .htaccess file, one for each URL or group of URLs, but it would be difficult to maintain as well as being very inefficient.
There's a simpler alternative. Rewrite (that's rewrite, not redirect) those requests to a special PHP script that then either looks in an array or in a database for the matching new URL. The PHP script then sends the 301 HEADER and the new location.
This rewrite will use a RewriteRule and be located after the rules which block malicious access and before your canonicalisation redirects.
You have to use a PHP script looking the new URL up because there is no way for mod_rewrite to "know" that ?cpath=20 on the old site matches /purple-widgets/ on the new site.
If you can, use extensionless URLs on your new site. It will make the pattern matching a whole lot easier. There is no need for the .php or .html suffix to appear in your new URLs.