开发者

htaccess redirect if url contains specific string

We've installed a new shop software and I've set up redirects for all of the old pages, but there's one that I just can't get to work. If the url includes

cp_tpl=productlist.html

then I want to redirect to the main website. So for example the old url could be

http://www.gocellular.ca/index.php?cp_tpl=productlist.html&cp_cat=803&cp_sid=1xxxxxx

and I want to redi开发者_C百科rect to

www.gocellular.ca

The 'cp_tpl=productlist.html' can be anywhere in the url - basically I just want to check if the string 'cp_tpl=productlist.html' is included anywhere in the url and then redirect. I've tried about 100 different .htaccess re-writes but just can't get this to work! I'd be very grateful for any ideas.... THANK YOU!


In order to catch that string in the query string as you have shown it there you have to use a RewriteCond, as the regular expression doesn't get checked against the query string in a redirect rule. Something like this should do the trick:

RewriteCond %{QUERY_STRING} cp_tpl=productlist.html
RewriteRule .* / [R,L]

The above will keep the query string intact. If yow want to remove the query string, just add a ? after /, i.e.:

RewriteRule .* /? [R,L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜