【问题标题】:Redirect url just printing to screen - python重定向网址只是打印到屏幕 - python
【发布时间】:2012-12-14 20:31:39
【问题描述】:

我编写了一个简单的 python 脚本来在点击广告后重定向一个 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")

【问题讨论】:

  • 如果您认为这可以解决您的问题,请选择已接受的答案。

标签: python url redirect cgi-bin


【解决方案1】:

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

【讨论】:

  • 完美运行!感谢您的帮助!
猜你喜欢
  • 2013-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多