rewrite or return for simple redirection

neubyr neubyr at gmail.com
Fri Nov 21 22:53:50 UTC 2014


On Fri, Nov 21, 2014 at 12:11 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:

> Hello!
>
> On Fri, Nov 21, 2014 at 12:06:54PM -0800, neubyr wrote:
>
> > On Fri, Nov 21, 2014 at 11:33 AM, Maxim Dounin <mdounin at mdounin.ru>
> wrote:
> >
> > > Hello!
> > >
> > > On Fri, Nov 21, 2014 at 11:21:40AM -0800, neubyr wrote:
> > >
> > > > I am trying to understand which option would result in more efficient
> > > HTTP
> > > > redirection. I am trying to redirect ^/address page to ^/contact
> page.
> > > >
> > > > Option 1:
> > > > rewrite ^/address /contact permanent;
> > > >
> > > > Option 2:
> > > > location ~ ^/address {
> > > >   return 301 $scheme://$host/contact
> > > > }
> > > >
> > > > Which option should be preferred? Both options involve regex and I
> am not
> > > > sure which one will be faster. Are there any other better options?
> > >
> > >     location = /address {
> > >         return 301 /contact;
> > >     }
> > >
> > >
> > >
> > Thank you Maxim!! That's helpful. I should have used precise location
> match
> > and relative redirect path.
> >
> > Also, can something with following rewrite be converted to 'location and
> > return' combination?
> >
> > rewrite ^/members/(.*)         /users/$1
> >
> > Or am I better with rewrite directive in this case? Appreciate any help.
>
> For such cases rewrite is better, IMHO.  In some cases it may be a
> good idea to additionally isolate it with prefix location, like
> this:
>
>     location /members/ {
>         rewrite ^/members/(.*) /users/$1 redirect;
>     }
>
>
Thank you Maxim. In what cases prefix might be a good idea??

- N
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20141121/2a09578e/attachment.html>


More information about the nginx mailing list