Forum Moderators: phranque

Message Too Old, No Replies

htacess help

         

ScottJay

4:36 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



Hi!

I need help creating a 301 permanent redirect rule that would behave as follows:

www.site.com/index.php?main_page=product_info&cpath=1&products_id=5
would redirect to:
www.site.com/index.php?main_page=product_info&products_id=5

However, it's not as easy as stripping out the cpath parameter. The cpath parameter should be stripped out if and only if the products_id parameter is present. For instance
www.site.com/index.php?main_page=product_info&cpath=1
would not redirect anywhere

Any help would be greatly appreciated.

RewriteEngine

6:32 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



I believe something like this should work out for you:

RewriteCond %{QUERY_STRING} ^main_page=product_info&cpath=(.+)&products_id=(.+)$ [NC]
RewriteRule ^index\.php http://www.example.com/index.php?main_page=product_info&products_id=%2 [R=301]

[edited by: RewriteEngine at 6:33 pm (utc) on Sep. 4, 2007]

[edited by: jdMorgan at 3:34 am (utc) on Sep. 5, 2007]
[edit reason] example.com [/edit]

ScottJay

6:54 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



Yes. Excellent! Thank you!

g1smd

12:18 am on Sep 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is cPath always the middle parameter?

If I remember rightly, some parts of osCommerce generate URLs with the same parameters and same parameter values, but with a different parameter order in the URL.