301 .htaccess重定向后面的查询/

时间:2012-07-25 11:03:44

标签: .htaccess redirect permanent

我一直在努力做几天的301重定向。现有主题都没有帮助。

我需要使用.htaccess重定向以下页面:

Redirect 301 http://www.mypage.com/?q=company/contacts http://www.mypage.com/contacts 
Redirect 301 http://www.mypage.com/?q=product/new/ghz/name-5 http://www.mypage.com/name-5

我知道我应该使用重写规则并指定{QUERY-STRING}并相信我,我已经尝试过了。什么都没有帮助。我非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

与实际请求匹配:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?q=company/contacts
RewriteRule ^$ http://www.mypage.com/contacts? [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?q=product/new/ghz/name-5
RewriteRule ^$ http://www.mypage.com/name-5? [R=301,L]

或查询字符串(这与重写的URI匹配)

RewriteCond %{QUERY_STRING} ^q=company/contacts$
RewriteRule ^$ http://www.mypage.com/contacts? [R=301,L]

RewriteCond %{QUERY_STRING} ^q=product/new/ghz/name-5$
RewriteRule ^$ http://www.mypage.com/name-5? [R=301,L]
相关问题