2013-04-23 23 views
2

我已经在.htaccess文件中设置了301重定向的数量,但我遇到了使重定向不匹配的查询字符串的问题。301重定向:匹配查询字符串,不要将它附加到新的重定向

例子:

Redirect 301 /about/history/?lang=fr http://www.newdomain.com/fr/history 
Redirect 301 /about/history/ http://www.newdomain.com/nl/history 

所以olddomain.com/about/history/?lang=fr现在匹配第二个规则和重定向到http://www.newdomain.com/nl/history?lang=fr

我希望它从字面上采用?lang=fr,而不是将querystring附加到新的重定向。

我该怎么做?

回答

2

Redirect需要一个URL-路径,它不包含查询字符串。所以,第一个Redirect从来没有匹配。

达到你想要什么,你可以尝试某种content negotiation或使用mod_rewrite

RewriteEngine on 
RewriteCond %{QUERY_STRING} lang=fr 
RewriteRule /about/history/ http://www.newdomain.com/fr/history? [R,L] 
RewriteRule /about/history/ http://www.newdomain.com/nl/history [R,L] 

如果一切正常,你期望的那样,你可以改变RR=301

+0

谢谢!我最终使用了PHP重定向,而在这种情况下效果更好。 – Joan 2013-04-23 18:51:04

相关问题