如果URL中包含特定字符串的htaccess重定向 [英] htaccess redirect if url contains specific string

查看:129
本文介绍了如果URL中包含特定字符串的htaccess重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经安装了新的软件商店,我已经设置了重定向所有的旧网页,但是有一个,我只是不能去上班。如果URL包括

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

cp_tpl=productlist.html

那么我想重定向到主网站。因此,例如旧的URL可以是

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

和我想重定向到

www.gocellular.ca

www.gocellular.ca

在'cp_tpl = productlist.html'可以随时随地在url - 基本上我只是想检查是否字符串cp_tpl = productlist.html'被包含在URL中的任意位置,然后重定向。我试着约100种不同的.htaccess重新写,但就是无法得到这个工作!我会非常感谢任何想法....谢谢!

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!

推荐答案

为了赶上该字符串的查询字符串,你已经证明它有你有使用的RewriteCond,作为常规EX pression没有按'吨得到核对的重定向规则的查询字符串。像这样的东西应该做的伎俩:

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]

这篇关于如果URL中包含特定字符串的htaccess重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆