301.htaccess在查询之后重定向/

301.htaccess在查询之后重定向/,.htaccess,redirect,permanent,.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-S

我一直在努力做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},相信我,我已经尝试过了。没有任何帮助。

与实际请求匹配:

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匹配)


它确实会重定向,但URL在这两种情况下都显示如下:它应该显示为mypage.com/contacts,仅此而已it@TomTom哦,忘了删除查询字符串,请参见编辑(结尾需要一个?)
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]