重定向url只是打印到屏幕python

2024-09-20 01:34:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了一个简单的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")


Tags: 代码pyimport脚本comhttpurlhtml
1条回答
网友
1楼 · 发布于 2024-09-20 01:34:18

“\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

相关问题 更多 >