将带有参数的网址重定向到首页网址 [英] Redirect urls with parameters to homepage url
本文介绍了将带有参数的网址重定向到首页网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下示例网址,我需要将其重定向到www.example.co.uk
I have the following example urls that i need redirecting to www.example.co.uk
- http://www.example.co.uk/wordpress/? feed = comments-rss2
- http://www.example.co.uk/wordpress/?feed= rss2
- http://www.example.co.uk/wordpress/?cat= 518
- http://www.example.co.uk/wordpress/?cat= 514
- http://www.example.co.uk/wordpress/?cat= 520
- http://www.example.co.uk/wordpress/?cat= 521
- http://www.example.co.uk/wordpress/?cat= 523
- http://www.example.co.uk/wordpress/?cat= 515
- http://www.example.co.uk/wordpress/?p= 119
- http://www.example.co.uk/wordpress/?feed=comments-rss2
- http://www.example.co.uk/wordpress/?feed=rss2
- http://www.example.co.uk/wordpress/?cat=518
- http://www.example.co.uk/wordpress/?cat=514
- http://www.example.co.uk/wordpress/?cat=520
- http://www.example.co.uk/wordpress/?cat=521
- http://www.example.co.uk/wordpress/?cat=523
- http://www.example.co.uk/wordpress/?cat=515
- http://www.example.co.uk/wordpress/?p=119
此列表还有更多网址,都带有wordpress/表示法.
There are many more urls further to this list that all have a wordpress/ notation.
我必须像这样为每个人写一个条件重写:
Would I have to write a conditional rewrite for each like this:
RewriteCond %{QUERY_STRING} ^feed=comments-rss2$
RewriteRule ^/wordpress/?(.*)$ http://www.example.co.uk [R=301,L]
RewriteCond %{QUERY_STRING} ^cat=518$
RewriteRule ^/wordpress/?(.*)$ http://www.example.co.uk [R=301,L]
或者我可以编写一条规则来重定向所有包含/wordpress的网址以重定向到www.example.co.uk
or is there a rule i can write that redirect all urls that have /wordpress in them to redirect to www.example.co.uk
推荐答案
我相信一个简单的规则就足够了:
I believe a single rule like would be suffice:
RewriteCond %{QUERY_STRING} (^|&)(feed|p|cat)=[^&]+ [NC]
RewriteRule ^wordpress(/.*)?$ http://www.example.co.uk/? [R=301,L,NC]
确保这是您的.htaccess中RewriteEngine On
行以下的第一条规则.
Make sure this is very first rule in your .htaccess just below RewriteEngine On
line.
这篇关于将带有参数的网址重定向到首页网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文