3

我编写了一个简单的 python 脚本来在点击广告后重定向一个 url。
与广告关联的 url 是http://server.example.com/redirect.py

的代码redirect.py如下所示:

import cgi
import cgitb

cgitb.enable()
print('Content-Type: text/html\n\n')
print('Location: http://www.finalurl.com')

然而,不是将请求重定向到www.finalurl.com点击广告时,最终的 url 只是简单地显示在浏览器窗口中。非常感谢所有帮助。

请注意,redirect.py脚本在/public_html/cgi-bin/文件夹中,并且脚本具有711权限。此外,目标 url 并不总是相同的 url,它基于数据库查询。该代码被简单地省略了。

我还尝试了包括:print ("Status: 301 Moved")

4

1 回答 1

4

'\n\n' 是 http 标头标记的结尾,请改用:

print 'Status: 301 Moved Permanently'
print 'Location: http://www.finalurl.com'
print 'Content-Type: text/html'
print # end of header
... # short html with the url
于 2012-12-30T06:41:26.893 回答