CGI redirection: let us discuss it further

Sullivan WxPyQtKinter sullivanz.pku at
Tue Mar 28 20:24:23 CEST 2006

> Just read the name of the server (os.environ['SERVER_NAME']) to work
> out what absolute URL to redirect to, whist still being portable.
> Here's some code I dug up that should also cope with non-default ports
> and SSL, if that's of any use:
>   ssl= os.environ.get('HTTPS', 'off') not in ('', 'off', 'false', 'no')
>   scheme= ['http', 'https'][ssl]
>   port= ['80', '443'][ssl]
>   host= os.environ.get('SERVER_NAME', 'localhost')
>   url= '%s://%s:%s' % (scheme, host, os.environ.get('SERVER_PORT',
> port))
>   if url.endswith(':'+port):
>     server= server[:-(len(port)+1)]
>   url+= path
> (You *can* pass relative URLs back to the web server in a Location:
> header, but this should do an internal redirect inside the server,
> which may not be what you want.)

Sorry I do not quite understand what is the difference between an
internal redirection and an external one?
> -- 
> And Clover
> mailto:and at

More information about the Python-list mailing list