Re: URL redirect

TSalm <[email protected]> Mon, 01 Aug 2011 21:27:54 +0200
Newsgroups gmane.comp.python.mod_python
Message-ID <[email protected]>
Le 30/07/2011 00:00, Kory Hamzeh a =E9crit :
> Hi Everyone,
>
> I'm having trouble doing a redirect using the 'Location:' keyword in th=
e
> 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"] =3D "301 Moved Permanently"
>          req.headers_out["Location:"] =3D "http://www.example.com/"
>          req.content_type =3D 'text/html'
>          return ""
>
> I get an empty page on he browser.
>
> I've also tried:
>
> Def index(req):
>
> 	If must_redirect:
> 	    s =3D """
> 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
>         =20
Maybe you could try to set status :
   req.headers_out["Location"] =3D "http://www.example.com"
   req.status =3D apache.HTTP_MOVED_TEMPORARILY