301重定向:匹配查询字符串,请勿将其附加到新的重定向中 [英] 301 redirects: match querystring, don't append it to new redirect

查看:67
本文介绍了301重定向:匹配查询字符串,请勿将其附加到新的重定向中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.htaccess文件中设置了301个重定向,但是查询字符串出现问题,导致重定向不匹配。

I've set up a number of 301 redirects in an .htaccess file, but I'm having problems with a query string that makes the redirect not match.

示例:

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

So olddomain.com/about/history/?lang=fr now matches the second rule and redirects to http://www.newdomain.com/nl/history?lang=fr.

我希望它接受?lang = fr 从字面上看,而不是将查询字符串附加到新的重定向中。

I want it to take the ?lang=fr literally and not append the querystring to the new redirect.

我该怎么做?

推荐答案

重定向 带有一个URL - path ,其中不包含查询字符串。因此,第一个重定向永远不会匹配。

Redirect takes an URL-path, which doesn't include the query string. So, the first Redirect never matches.

要实现您想要的目标,可以尝试某种内容协商,或使用 mod_rewrite

To achieve what you want, you can try some sort of content negotiation or use 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]

当一切正常运行时,您可以将 R 更改为 R = 301

When everything works as you expect, you can change R to R=301.

这篇关于301重定向:匹配查询字符串,请勿将其附加到新的重定向中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆