[mod_python] URL redirect

TSalm TSalm at free.fr
Mon Aug 1 15:27:54 EDT 2011


Le 30/07/2011 00:00, Kory Hamzeh a écrit :
> Hi Everyone,
>
> I'm having trouble doing a redirect using the 'Location:' keyword in the
> header. My code, near the top of the handler is:
>
> Def index(req):
>
>      # determine is we need a redirect. Set must_redirect to True is so ....
>
>      if must_redirect:
>          req.headers_out["HTTP/1.1"] = "301 Moved Permanently"
>          req.headers_out["Location:"] = "http://www.example.com/"
>          req.content_type = 'text/html'
>          return ""
>
> I get an empty page on he browser.
>
> I've also tried:
>
> Def index(req):
>
> 	If must_redirect:
> 	    s = """
> HTTP/1.1 301 Moved Permanently
> Location: http://www.example.org/
> Content-Type: text/html
> """
>          return s
>
> I get a page with that exact text on it.
>
> I'm using a publisher handler.
>
> What am I doing wrong?
>
> Thanks,
> Kory
>          
Maybe you could try to set status :
   req.headers_out["Location"] = "http://www.example.com"
   req.status = apache.HTTP_MOVED_TEMPORARILY



More information about the Mod_python mailing list