Forum Moderators: phranque
this part here works correctly...
RewriteCond %{QUERY_STRING} ^cPath=46$
RewriteRule ^index\.php$ /product_info.php?products_id=693 [R=301,L]
but this only forwards /index.php?cPath=46 to /product_info.php?products_id=693
but sometimes the link will be /index.php?cPath=46&osCsid=g7crucvfas6ejfkbas7o46eig2
how do I get it to catch both /index.php?cPath=46 AND /index.php?cPath=46&osCsid=g7crucvfas6ejfkbas7o46eig2
the part after &osCsid= will always be random so I'm not sure how to do this...
thank you!
Change $ to be &? (ampersand followed by question mark) to allow another parameter to follow.
Your target should include the domain name so that it fixes www and non-www issues for *this* '46' URL within *this* rule.
Your rule caters for '/index.php' but does not cater for just '/' and that is a problem. Make it cater for both URLs.
You didn't say whether the osCid parameter was to be 'dropped' in the redirect, or whether it carries over.
here is the entire .htaccess
RewriteEngine OnRewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{QUERY_STRING} ^cPath=46&?
RewriteRule ^index\.php$ /product_info.php?products_id=693 [R=301,L]
I still need to fix the www and non-www issue even though I have that first cond/rule set?
thanks for your reply.
Consider a non-www request for cpath=46.
First rule redirects to www.
Second rule redirects to 'product.info'.
You have a Redirection Chain.
PageRank is *lost* on the second redirect.
Add the domain name to the target of the second rule. Fix it so that both 'index.php' and '/' trigger the rule.
Swap the order of the two rules so that the generic 'non-www to www' rule is listed last.
Be aware that your non-www redirect code does not fix a www request with appended port number leaving it open to Duplicate Content indexing. There's better code for this redirect, code that does not leave such a 'hole'.
As you haven't escaped the period on one of the conditions, be aware that the rule would work for a domain name of example.com as well as exampleZcom or example~com or example8com etc.
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^cPath=46(&.*)?$
RewriteRule ^(index\.php)?$ http://www.example.com/product_info.php?products_id=693%1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]