Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
重定向url仅打印到屏幕-python_Python_Url_Redirect_Cgi Bin - Fatal编程技术网

重定向url仅打印到屏幕-python

重定向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

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

工作完美!谢谢你的帮助!如果您认为这可以解决您的问题,请选择已接受的答案。