Wednesday, November 23, 2011

URI redirection in mod_wsgi scripts

See this simple example:
def application(environ, start_response):
    if environ['REQUEST_METHOD']!='GET':
        start_response('301 Redirect', [('Location',  http://example.com'),])
        return []

    response_headers = [
        ('Content-Length', str(len(output))),
        ('Content-Type', 'text/plain'),
    ]

    start_response('200 OK', response_headers)

    return ["Hello World"]

No comments:

Post a Comment