urllib redirect

François Pinard pinard at iro.umontreal.ca
Fri Apr 28 16:37:12 EDT 2000

Georg Mischler <schorsch at schorsch.com> writes:

> Anthony J Wilkinson wrote:

> > If you just print out the following you can use the browser's own
> > redirection facility.
> >
> > <html>
> >     <head>
> >         <meta HTTP-EQUIV="REFRESH" CONTENT="0; URL=http://www.spam.com/">
> >         <title> redirect page</title>
> >     </head>
> >     <body>
> >         If your browser does not support redirection, click
> >         <a HREF="http://www.spam.com/">here</a> to continue.
> >     </body>
> > </html>

> This can be done in a much simpler way, whitout sending any
> actual page data to the client:

>   your_new_path = 'http://www.spam.com/'

>   print 'Status: 302 Redirected'
>   print 'Location: %s' your_new_path

> As soon as the browser (works with *every* browser!) sees the
> "Location:" header, it will stop and try fetching the new page.

The advantage of the HTML code is that it is mere HTML, so usable wherever
an HTML page was used.  Even if the second solution is simpler, it is only
usable through a CGI script, that is, from a location allowing execution
of CGI scripts.  It happened to me that this is exactly _because_ the
original is at a place forbidding CGI scripts, that I need page relocation.
So the original HTML solution is worth being noted, at least for some cases.

François Pinard   http://www.iro.umontreal.ca/~pinard

More information about the Python-list mailing list