.htaccess 301 重定向将查询附加到 URL 末尾
我希望有人可以帮助解决不寻常的情况。
我的 httpd.conf 文件中有一个主要的重写规则,用于处理所有动态内容。 如下所示并且工作正常:
RewriteRule ^(.)(/./d/[^.]*)$ /category/refine.cgi\?\&a\=$2
该规则 我遇到的问题是,当我尝试使用 .htaccess 创建简单的 301 重定向时,查询参数会自动附加到 URL 的末尾,因此最终结果如下所示:
http://www.example.com/category/page.html?& a=/category/subcategory/something/d/page/
请注意,使用 .htaccess 创建 301 重定向时,查询字符串会附加到 URL 中。
我有针对具体情况的解决方案,但每次我想要执行简单的 301 重定向时创建新规则是不切实际的。
所以,我想知道是否可以以任何方式编辑我的“主要规则”,以便当使用 .htaccess 创建重定向时,查询参数不会附加到目标 URL。
预先感谢您可以提供的任何帮助。
I am hoping someone can help with an unusual situation.
I have one main rewrite rule in place in my httpd.conf file which handles all of our dynamic content. The rule looks like this and works fine:
RewriteRule ^(.)(/./d/[^.]*)$ /category/refine.cgi\?\&a\=$2
The problem I have is that when I try to use .htaccess to create a simple 301 redirect, the query parameters are automatically appended to the end of the URL's so the final result looks like this:
http://www.example.com/category/page.html?&a=/category/subcategory/something/d/page/
Notice that the query string is appended to the URL when using .htaccess to create a 301 redirect.
I have solution for this on a case-by-case basis, but it's not practical to create a new rule each time I want to do a simple 301 redirect.
So, I am wondering if I can edit my "main rule" in any way so that when .htaccess is used to create redirects, the query parameters are not appended to the target URL.
Thanks in advance for any help you can provide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有多个简单的重定向,您想要抑制查询字符串值,您可以将所有重定向放在 RewriteMap(因为您已经有权访问 httpd.conf),并且拥有一个 .htaccess 规则来抑制查询字符串,如下所示
放置在 htaccess
放置在httpd.conf
/usr/local/apache/conf/redirect.map 的内容
键后跟一个空格,后跟目标
If you have multiple simple redirects for which you want to suppress query string values you could put all the redirects in a RewriteMap (since you already have access to httpd.conf), and have one .htaccess rule that suppresses the query strings as below
place in htaccess
place in httpd.conf
contents of /usr/local/apache/conf/redirect.map
key followed by a space followed by target
这就是您的规则定义它要执行的操作:
它表示创建一个如下所示的 URL:
category/refine.cgi?&a=/foo/bar/
如果您不希望发生这种情况,请将规则更改为:
That's what your rule has defined it to do:
It says to create a URL that will look like:
category/refine.cgi?&a=/foo/bar/
If you don't want that to happen, change your rule to be: