重定向url只是打印屏幕python



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

redirect.py的代码如下:

import cgi
import cgitb
cgitb.enable()
print('Content-Type: text/htmlnn')
print('Location: http://www.finalurl.com')

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

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

我也试过包括:print ("Status: 301 Moved")

'nn'是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

最新更新