2

我在 .htaccess 文件中设置了多个 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字面意思,而不是将查询字符串附加到新的重定向中。

我怎么做?

4

1 回答 1

2

Redirect接受一个不包含查询字符串的 URL- path 。所以,第一个Redirect永远不匹配。

要实现您想要的,您可以尝试某种内容协商或使用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.

于 2013-04-23T07:18:35.517 回答