简体   繁体   English

301使用查询字符串重定向URL?

[英]301 Redirect url with query string?

I like to do the following redirection: 我喜欢执行以下重定向:

domain.de/?file=team ––> domain.de/team.html domain.de/?file=team- > domain.de/team.html

To do this I try the following rewriting (that is'nt working): 为此,我尝试进行以下重写(不起作用):

RewriteCond %{QUERY_STRING} ^file=team$
RewriteRule ^/$ /team.html [L,R=301]

How can I do this 301 redirection? 我该如何进行301重定向?

Got the solution by my self: 我自己找到了解决方案

RewriteCond %{QUERY_STRING} ^file=team$
RewriteRule ^$ /team.html? [L,R=301]

domain.de/?file=team ––> domain.de/team.html domain.de/?file=team-> domain.de/team.html

If you see my question above I've made the following two mistakes: 如果您在上面看到我的问题,我犯了以下两个错误:

1. Mistake: Missing Question Mark 1.错误:缺少问号

If you remove the question mark then the query_string will not be removed: 如果删除问号,则不会删除query_string:

RewriteRule ^$ /team.html [L,R=301]

domain.de/?file=team ––> domain.de/team.html?file=team domain.de/?file=team-> domain.de/team.html?file=team

Just a further hint by the way the command RedirectMatch is not able to remove query_strings. 只是命令RedirectMatch无法删除query_strings的进一步提示。

2. Mistake: Wrong Rewrite Path 2.错误:错误的重写路径

 RewriteRule ^\$ ... does not match doamin.de/?file=team
 RewriteRule ^$ ... matches

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM