Apache CGI重定向到绝对URI不起作用 [英] Apache CGI redirect to absolute URI doesn't work

查看:145
本文介绍了Apache CGI重定向到绝对URI不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上以控制台方式运行Apache 2.2.13。我已经制作了一个可执行文件来处理请求。在某些情况下,当它检测到指向目录的URL但没有尾随斜杠时,它将尝试重定向到附加了斜杠的相同URL。退出代码设置为301。很奇怪,在响应标头中包含退出代码无效:

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/

但是这样做:

Location: something/

难道我做错了什么?还是我发现了Apache中的错误? (如果是这样,我应该在哪里以及如何发布它最好?)

Am I doing something wrong? Or did I discover a bug in Apache? (If so, where and how should I post it best?)

推荐答案

通常,位置包含完整的URL,包括http:和主机名。 DVK就是这种情况。

Usually, 'Location' contains a full URL, including http: and the hostname. This is the case outlined by DVK.


位置:/cgi-bin/mycgi.exe/something /

Location: /cgi-bin/mycgi.exe/something/

这实际上是另一回事:内部重定向。它是由 CGI规范定义的,并且可以在衍生自某些其他服务器环境中使用CGI,例如PHP。当Location包含虚拟路径时,Apache会立即在该路径中提供页面/脚本,而浏览器不会知道存在任何重定向。

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.

显然不是您想要的,因为当浏览器永远不会看到它是301时,就没有必要执行301内部重定向。

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.


位置: something /

Location: something/

另一方面,这没什么。它不是完整的URL,也不是虚拟路径,因为它不是以 /开头。 Apache不知道如何处理它,因此只猜测它不是虚拟路径,因此将其吐回到浏览器中,而无需进一步评论。

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.

在位置标头中将其发送到浏览器是无效的,但是无论如何,许多人还是允许它,这就是为什么它可以工作的原因。确实,您应该传递完整的URL:

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:

Location: http://www.example.com/cgi-bin/mycgi.exe/something/

这篇关于Apache CGI重定向到绝对URI不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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