6

How to do simple http redirect using Python? without using meta.

UPDATE:

I am using Python 2.7.1 as a CGI from within the cgi-bin directory of Apache.

3
  • This depends entirely on what web framework you're using. Commented Mar 16, 2011 at 4:08
  • 1
    for http redirect you should output header with content location: newUrl to the client. To send headers, use appropriate function on your framework. Commented Mar 16, 2011 at 4:10
  • 1
    I am using Python as a CGI script from within the cgi-bin directory of apache. Commented Mar 16, 2011 at 4:15

1 Answer 1

6

To redirect using your current setup (CGI apache):

print("Location:http://newurl.com/foobar")
print # to end the CGI response headers.
Sign up to request clarification or add additional context in comments.

3 Comments

am getting a "Premature end of script headers" error. The print statement is my first line after #!/Python27/python.
The url of browser(Chrome) seems not change
While this works fine in Chrome on my desktop, on my ipad get a safari error saying "too many redirects"... any ideas? I tried emptying the cache on the ipad.. but no luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.