301使用查询字符串重定向网址?
问题描述:
我喜欢做以下重定向:301使用查询字符串重定向网址?
domain.de/?file=team - >domain.de/team.html
要做到这一点,我尝试以下方法改写(即is'nt working):
RewriteCond %{QUERY_STRING} ^file=team$
RewriteRule ^/$ /team.html [L,R=301]
我该如何做301重定向?
答
得到解决由我自己:
RewriteCond %{QUERY_STRING} ^file=team$
RewriteRule ^$ /team.html? [L,R=301]
domain.de/?file=team - > domain.de/team.html
如果你看到上面我的问题我犯了以下两个错误:
1.错误:缺少问号
如果删除了问号,则QUERY_STRING不会被删除:
RewriteRule ^$ /team.html [L,R=301]
domain.de/?file=team - > domain.de/team.html?file=team
通过命令RedirectMatch无法删除query_strings的方式提供了进一步的提示。
2.错误:错误的重写路径
RewriteRule ^\$ ... does not match doamin.de/?file=team
RewriteRule ^$ ... matches
的'^/$'正则表达式不起作用,因为前缀(斜线)在以每个处理规则时,被剥离的路径目录上下文,就像在''容器中一样。通过扩展,htaccess文件中的所有规则都是每个目录,因为它们应用于htaccess文件所在目录的上下文中。 –
您的评论刺激了我,因为我没有写过'^/$'...我写了'^\ $' –
你的问题说:“'重写规则^/$ /team.html [L,R = 301]'' –