我有一个用Python编写的独特的CGI脚本, 让我们把它称为peculiar.py ,我想“回答”任何和所有的HTTP请求到一个特定的目录和它下面的任何东西,然后捕获环境variables的原始URL。 原来的url稍后会被使用。 到目前为止,我正在尝试redirect到默认文档,然后调用相关的环境variables。 我还没有find任何相关的东西。
概念演练如下所示:
http://site.domain.tld/videos/fun-stuff.html这样的URL。 http://site.domain.tld/redirect-source/2013-01-10/ 。 http://site.domain.tld/redirect-source/2013-01-10/请求。 http://site.domain.tld/redirect-target/ 。 Peculiar.py作为http://site.domain.tld/redirect-target/的默认文档被唤醒。 http://site.domain.tld/redirect-source/2013-01-10/ 。 我最初的步骤是:
将peculiar.py设置为“redirect-target”目录中的默认文档,以便http://site.domain.tld/redirect-target/可以通过http://site.domain.tld/redirect-target/peculiar.py回答http://site.domain.tld/redirect-target/peculiar.py 。 这工作。
使用HTTPredirectfunction,所以http://site.domain.tld/redirect-source/subdir1/item1.ext将被redirect到http://site.domain.tld/redirect-target/并通过http://site.domain.tld/redirect-target/peculiar.py 。 这工作。
尝试获取环境variables并find一个好的引用。 (或者是referer ,就像referer拼写错误一样)
现在, peculiar.py只是抓住所有的环境variables,并把它们吐出来作为HTML,所以我可以检查它们。
我发现,当我使用Found (302) , Permanent (301)甚至是Temporary (307)设置HTTPredirect时,我可以pipe理redirect,但是我无法获得原始URL。 如果我访问http://site.domain.tld/redirect-source/subdir1/item1.ext就不会显示在环境variables列表中。 如果我将http://site.domain.tld/redirect-source/subdir1/item1.ext作为超链接embedded到网页中, HTTP_REFERER确实出现在环境variables列表中,但它只显示原始网页。
看起来好像redirect只是…跳过引荐。 是因为引用者是从客户端传过来的,而不是服务器端呢?
背景是,我正在构build一个脚本,为Quicktime(二进制文件,即时构build)和QTL文件提供参考电影,两者都会根据原始URL调用。 是的,这是很多工作,以避免链接querystrings。
我在这里错过了很明显的东西吗 redirect是在特定目录下回答所有URL的错误工具吗? 我是否缺lessweb.config一个设置,其中我大部分是无知的?
我打开其他的方法,只要我可以使用Python和IIS。
我认为你的问题是,它是未定义的是否发送Referer头响应HTTP / 301或HTTP / 302。 请记住,在HTTPredirect中,服务器向301/302发送新的位置标题,但浏览器是重新请求的(并决定是否添加位置标题)。
你最好的select可能是传回301/302中Referer的原始值作为querystring参数,例如(pseudo):
HTTP/1.1 302 Found Location: http://site.domain.tld/redirect-target/?orig=http://site.domain.tld/redirect-source/2013-01-10/
然后在Python脚本中捕获orig的值。
您可能需要使用Response.Redirect()来执行实际redirect的自定义ASP,而不是依赖于内置的IISfunction。
更多: https : //stackoverflow.com/questions/2158283/will-a-302-redirect-maintain-the-referer-string