【发布时间】:2011-08-30 01:32:21
【问题描述】:
CherryPy 是否可以将 HTTP 重定向到 HTTPS。例如,假设下面的代码是 http://example.com,如果有人通过 https://example.com 访问我希望他们被重定向到纯 HTTP URL(可能是 301 重定向?)我该怎么做?
#!/usr/bin/env python
from pprint import pformat
from cherrypy import wsgiserver
def app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
start_response(status, response_headers)
return [pformat(environ)]
server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 80), app)
try:
server.start()
except KeyboardInterrupt:
server.stop()
【问题讨论】:
-
为什么在 CherryPy 中这样做,而 Apache 可以更有效地做到这一点?
标签: python http https wsgi cherrypy