Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do simple http redirect using Python?

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.
like image 329
Babiker Avatar asked Mar 16 '11 04:03

Babiker


People also ask

How do you get a redirected URL in python?

Use Python urllib Library To Get Redirection URL. request module. Define a web page URL, suppose this URL will be redirected when you send a request to it. Get the response object. Get the webserver returned response status code, if the code is 301 then it means the URL has been redirected permanently.

How do I redirect using HTTP?

Principle. In HTTP, redirection is triggered by a server sending a special redirect response to a request. Redirect responses have status codes that start with 3 , and a Location header holding the URL to redirect to. When browsers receive a redirect, they immediately load the new URL provided in the Location header.

How do I redirect to another page in python?

url_for() Another method you can use when performing redirects in Flask is the url_for() function. The way that url_for() works is instead of redirecting based on the string representation of a route, you provide the function name of the route you want to redirect to.


1 Answers

To redirect using your current setup (CGI apache):

print("Location:http://newurl.com/foobar")
print # to end the CGI response headers.
like image 162
Mike Lewis Avatar answered Oct 23 '22 05:10

Mike Lewis