I’ve been wrestling with this seemingly simple re-direct task for hours now and for the life of me cannot get it going.. Whether I pass in the value of 1 or 19 in url, in both cases it re-directs me to http://mywebsite.com/catalogue-gifts/chicks. (ideally, I want the second condition/rule to bring user to http://mywebsite.com/catalogue-gifts/mango-fruit-trees/)
Below is what I have:
RewriteCond %{QUERY_STRING} pID=1<br />
RewriteRule ^product_details2\.asp$ http://mywebsite.com/catalogue-gifts/chicks$1? [L,R=301]
RewriteCond %{QUERY_STRING} pID=19<br />
RewriteRule ^product_details2\.asp$ http://mywebsite.com/catalogue-gifts/mango-fruit-trees$1? [L,R=301]
Any help is much appreciated.. Thanks
This is because the
RewriteCondmatch is a regular expression with bounds. Therefore, if you have in the query string:it will match
pID=1, because it doesn’t check the end of the query string,pID=1is part ofpID=19.You need to change your conditions to:
and
The
(&|$)at the end means after those numbers, you have either a&character (for another parameter) or the end of the string ($).Additionally, if you are worried about other query string parameters that may end with a
pID, likefoopID, then you should add a boundary check to the front of those regex, like this:So the
(^|&)is either the beginning of the query string, or a&character.