homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Page by page redirect with query strings

5+ Year Member

Msg#: 4433392 posted 7:54 am on Mar 26, 2012 (gmt 0)

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




WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4433392 posted 8:03 am on Mar 26, 2012 (gmt 0)

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.


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

Msg#: 4433392 posted 10:38 am on Mar 26, 2012 (gmt 0)

If I understand the problem correctly, this thread may help:


5+ Year Member

Msg#: 4433392 posted 6:51 pm on Apr 3, 2012 (gmt 0)

incrediBILL - that thread was a life saver

Thanks a TON!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved