rewrite to www EXCEPT for one directory

Valentin V. Bartenev ne at vbart.ru
Fri Sep 7 00:14:20 UTC 2012


On Friday 07 September 2012 02:51:35 eddy at sdf.org wrote:
> > On Friday 07 September 2012 00:32:48 eddy at sdf.org wrote:
> > 
> > And please do not use ugly rewrites instead of simple "return", where
> > it's possible.
>
> maybe it's a stupid question, but: if 'permanent - returns permanent
> redirect with code 301' (http://wiki.nginx.org/HttpRewriteModule), then
> why one should use 'return 301 URL' instat?

Because the "return" directive is a simple construction that doesn't involve 
execution of regular expressions, and looks more declarative.

Moreover, you do not need to capture full URI, when you have variables like $uri 
and $request_uri. Therefore, something like ^(.*)$ is just a waste of resources.

> or its more about to avoid rewriting rules generaly? if yes, why is this
> so? a few weeks ago, i followed a discussion about to avoid if-rules
> because of performance with large rule sets. but i can't see this argument
> with one rewriting rule, which only takes action at first connect from
> client to server.

This is less about performance, but rather it's more about keeping config clean 
and simple.

> it's just a little bit confusing for me 'cause of so many poorly writen
> config examples around the web, and it's the first time i see this way
> with 'return 301 URL' for redirecting example.org to www.example.org.
> 

So many examples and tutorials around the web have written by guys who
have little understanding of the subject. And often they just copy-paste 
configuration from each other.

But in this particular case, it is worth to bear in mind, that early
versions of nginx doesn't support 'return 30x URL'.

See the official documentation for details: http://nginx.org/r/return

 wbr, Valentin V. Bartenev

--
http://nginx.org/en/donation.html
http://nginx.com/support.html



More information about the nginx mailing list