.htaccess 301重定向规则

时间:2013-09-04 09:41:17

标签: .htaccess redirect url-redirection

有人可以告诉我如何编写重写规则:我有许多链接看起来像:

http://www.mavrica.com/index.php?eID=tx_cms_showpic&file=uploads%252Fpics%252Fmozic_05.jpg&width=800m&height=600m&bodyTag=%253Cbody%2520bgcolor%253D%2522black%2522%253E&wrap=%253Ca%2520href%253D%2522javascript%253Aclose()%253B%2522%253E%2520%257C%2520%253C%252Fa%253E&md5=025892981ebd7f312b96276beb3ee194

我想将所有这些内容重定向到http://www.mavrica.com/fotogalerije/

所有链接都有共同的第一部分(最多为tx_cms_showpic)。

我尝试了以下htaccess规则:

RewriteRule /index.php?eID=tx_cms_showpic$ http://mavrica.com/fotogalerije/ [R=301]

RedirectMatch 301 ^/index.php?eID=tx_cms_showpic(.*) http://www.mavrica.com/fotogalerije/

但它们都不起作用。

我错过了什么?

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

您需要使用%{QUERY_STRING}来捕获和/或匹配网址的查询字符串部分:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?eID=tx_cms_showpic [NC]
RewriteRule ^ http://mavrica.com/fotogalerije/? [R=301,L]