0

I am trying to rewrite all the old oscommerce links to a new website. But I am having trouble with part of the URL I need to rewrite.

The link looks like this:

http://www.domain.com/product_info.php?cPath=3_72&products_id=129&osCsid=6j3iabkldjcmgi3s1344lk1285

This rewrite works for the above link:

RewriteCond %{REQUEST_URI}  ^/product_info\.php$
RewriteCond %{QUERY_STRING} ^cPath=3_72&products_id=129&osCsid=([A-Za-z0-9-_]+)$
RewriteRule ^(.*)$ http://www.domain.com/apple/air.html? [R=301,L]

But will not work for:

http://www.domain.com/product_info.php?cPath=3_72&products_id=129

My problem is that I want the rewrite to work no matter if the &osCsid=6j3iabkldjcmgi3s1344lk1285 part is included or not.

Cudos
  • 5,733
  • 11
  • 50
  • 77

2 Answers2

3

I think you can achieve this by not specifying the closing delimiter ($)

Give this a try:

RewriteCond %{REQUEST_URI}  ^/product_info\.php$
RewriteCond %{QUERY_STRING} ^cPath=3_72&products_id=129
RewriteRule ^(.*)$ http://www.domain.com/apple/air.html? [R=301,L]

By not putting the $ at the end of the regex string you are basically saying: match any string that starts with ..., no matter what comes after

Hope this helps :)

Tom Knapen
  • 2,277
  • 16
  • 31
1

This should do the job just fine:

RewriteCond %{QUERY_STRING} ^cPath=3_72&products_id=129
RewriteRule ^product_info\.php$ http://www.domain.com/apple/air.html? [R=301,L]
  1. There is no need for separate condition RewriteCond %{REQUEST_URI} ^/product_info\.php$ -- this part can be (actually, SHOULD BE, for better performance) moved to RewriteRule.

  2. This is enough ^cPath=3_72&products_id=129 -- it tells "When query strings STARTS with ...". No need to include optional/non-important parameters osCsid=([A-Za-z0-9-_]+).

  3. This rule is to be placed in .htaccess file in website root folder. If placed elsewhere some small tweaking may be required.

LazyOne
  • 158,824
  • 45
  • 388
  • 391