Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Page by page redirect with query strings

7:54 am on Mar 26, 2012 (gmt 0)

5+ Year Member

so friends, here is the situation.

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

Totally lost here...need help

8:03 am on Mar 26, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

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.
10:38 am on Mar 26, 2012 (gmt 0)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

If I understand the problem correctly, this thread may help:
6:51 pm on Apr 3, 2012 (gmt 0)

5+ Year Member

incrediBILL - that thread was a life saver

Thanks a TON!

Featured Threads

Hot Threads This Week

Hot Threads This Month