Apache CGI 重定向到绝对 URI 不起作用
我在 Windows 上以控制台模式运行 Apache 2.2.13。我制作了一个处理请求的可执行文件。在某些情况下,当它检测到指向目录但没有尾部斜杠的 URL 时,它会尝试重定向到附加了缺少的斜杠的同一 URL。退出代码设置为 301。奇怪的是,在响应标头中包含此代码不起作用:
Location: /cgi-bin/mycgi.exe/something/
但这确实有效:
Location: something/
我做错了什么吗?或者我发现了 Apache 中的错误? (如果是这样,我应该在哪里以及如何发布它最好?)
I have Apache 2.2.13 running in console mode on Windows. I have made an executable that handles requests. In a certain case, when it detects a URL pointing to a directory but has not trailing slash, it tries to redirect to the same URL with the missing slash appended. The exit-code is set to 301. Strangely enough, having this in the response header doesn't work:
Location: /cgi-bin/mycgi.exe/something/
but this does:
Location: something/
Am I doing something wrong? Or did I discover a bug in Apache? (If so, where and how should I post it best?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,“位置”包含完整的 URL,包括 http: 和主机名。 DVK 概述的就是这种情况。
这实际上是其他东西:内部重定向。它由CGI 规范定义,并可在源自以下的一些其他服务器环境中工作: CGI,例如 PHP。当 Location 包含“虚拟路径”时,Apache 会立即在该路径中提供页面/脚本,而浏览器不知道存在任何类型的重定向。
显然这不是您想要的,因为当浏览器永远看不到它是 301 时,执行 301 内部重定向是没有意义的。
另一方面,这没什么。它不是完整的 URL,也不是虚拟路径,因为它不以“/”开头。 Apache 不知道如何处理它,因此它只是猜测它不是虚拟路径,因此将其返回给浏览器,没有进一步的注释。
将其在“位置”标头中发送到浏览器是无效的,但许多浏览器无论如何都会允许它,这就是它看起来有效的原因。实际上,您应该传递完整的 URL:
Usually, 'Location' contains a full URL, including http: and the hostname. This is the case outlined by DVK.
This is actually something else: an internal redirect. It is defined by the CGI specification and works in some other server environments derived from CGI, such as PHP. When Location contains a 'virtual path', Apache serves up the page/script in that path straight away, without the browser knowing there was any kind of redirect.
Obviously that's not what you want as it makes no sense to do a 301 internal redirect when the browser will never see that it's a 301.
This, on the other hand, is nothing. It's not a full URL and it's not a virtual path as it doesn't begin with '/'. Apache doesn't know what to do with it, so it just guesses that it isn't a virtual path so spits it back to the browser with no further comment.
It's invalid to send this in a 'Location' header to a browser, but many of them will allow it anyway, which is why it appears to work. Really you should be passing the full URL:
1) 需要明确的是,重定向功能(例如“看到“位置:http 响应时该怎么做”)位于您的浏览器中,而不是 Apache 中。我想您知道这一点,但想确保它清楚。它在这里相关的原因是因为根据RFC,301响应中的地址需要是“单个绝对URI”。因此,您的 URI 示例缺少您的域名,例如需要为 http:// /your.web.server/cgi-bin/mycgi.exe/something/
虽然某些 Web 客户端接受带有相对重定向的 301,但其他客户端则不接受。
2) 您能否准确说明“不起作用”的含义,包括客户端错误和 Apache 日志中的任何错误?谢谢
另外,请指定以下哪些 URL 在客户端有效,哪些无效:
谢谢
1) Just to be clear, the redirection functionality (e.g. "what to do when seeing "Location: http response) is in your browser, not in Apache. I assume you know that but wanted to make sure it's clear. The reason it's relevant here is because as per the RFC, the address in 301 response needs to be "a single absolute URI". So your URI example is missing your domain name, e.g. needs to be http://your.web.server/cgi-bin/mycgi.exe/something/
While some web clients accept 301 with relative redirect, others do not.
2) Can you please specify exactly what you mean by "does not work" including client's error and any errors in Apache's log? Thanks
Also, please specify which of the following URLs work from the client and which do not:
Thanks