重定向url仅打印到屏幕-python
我编写了一个简单的python脚本,用于在单击广告时重定向url。重定向url仅打印到屏幕-python,python,url,redirect,cgi-bin,Python,Url,Redirect,Cgi Bin,我编写了一个简单的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.fina
与广告关联的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.finalur.com
,而是在浏览器窗口中显示最终url。非常感谢您的帮助
请注意,redirect.py
脚本位于/public\u html/cgi bin/
文件夹中,并且该脚本具有711
权限。此外,目标url并不总是相同的url,它基于数据库查询。该代码被简单地省略了
我还尝试包括:
print(“Status:301 Moved”)
“\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
工作完美!谢谢你的帮助!如果您认为这可以解决您的问题,请选择已接受的答案。