Welcome! Log In Create A New Profile

Advanced

Re: Permanent redirection with regex after moving blog

August 13, 2009 09:50AM
On Thu, Aug 13, 2009 at 04:05:46PM +0300, Marcus Clyne wrote:

> Igor Sysoev wrote:
> >On Thu, Aug 13, 2009 at 12:43:14PM +0300, Marcus Clyne wrote:
> >
> >
> >>miles wrote:
> >>
> >>>location ^~ /weblog/ {
> >>>rewrite ^/weblog/(.*) /blog/$1 permanent;
> >>>}
> >>>
> >>>location ~ ^/weblog/(.*) {
> >>>rewrite ^ /blog/$1 permanent;
> >>>}
> >>>
> >>>You should use the first method.
> >>>
> >>>Thanks so much, Igor - will do!
> >>>
> >>>Posted at Nginx Forum:
> >>>http://forum.nginx.org/read.php?2,4895,4912#msg-4912
> >>>
> >>>
> >>>
> >>Would
> >>
> >>location /weblog/ {
> >>rewrite ^/weblog/(.*) /blog/$1 permanent;
> >>}
> >>
> >>not be a little more efficient?
> >>
> >
> >"location ^~ /weblog/" is more efficient than "location /weblog/" because
> >"^~" disables testing any regex locations. If server has no regex
> >locations,
> >then these two locations are equal.
> >
> >
> What about when you have no regexes - will the non-regex location be
> marginally faster because it doesn't involve the pcre library (i.e. just
> strncmp) (I've not looked at that bit of source code, but I'm assuming
> you don't use the overhead of initing a pcre struct for just checking
> the first characters of the uri)?

Static locations are better because:

1) they are slightly faster, nginx looks them in some kind of binary tree
with addition of inclusive nodes, while regex location are run until
one will match.

2) static locations allow to write scalable configurations: you just
need to add yet another location and you do not worry about some
conflicts with other locations: for example, at the moment I have
158 static (and only static!) locations at www.rambler.ru.

As to regexes, if you write "~/~*" then nginx calls PCRE without
any checking and optimizations. BTW, PCRE does not test "\.(gif|jpg|...)$"
or even "\.php$" from the end as perl does. Probably, it should be
optimized, at least the later case.


--
Igor Sysoev
http://sysoev.ru/en/
Subject Author Posted

Permanent redirection with regex after moving blog

miles August 12, 2009 04:42PM

Re: Permanent redirection with regex after moving blog

meto August 12, 2009 05:00PM

Re: Permanent redirection with regex after moving blog

miles August 12, 2009 05:07PM

Re: Permanent redirection with regex after moving blog

meto August 12, 2009 05:09PM

Re: Permanent redirection with regex after moving blog

miles August 12, 2009 05:17PM

Re: Permanent redirection with regex after moving blog

Igor Sysoev August 13, 2009 03:12AM

Re: Permanent redirection with regex after moving blog

miles August 13, 2009 03:55AM

Re: Permanent redirection with regex after moving blog

Nick Pearson August 12, 2009 05:07PM

Re: Permanent redirection with regex after moving blog

miles August 12, 2009 05:33PM

Re: Permanent redirection with regex after moving blog

Igor Sysoev August 13, 2009 03:10AM

Re: Permanent redirection with regex after moving blog

miles August 13, 2009 03:54AM

Re: Permanent redirection with regex after moving blog

Marcus Clyne August 13, 2009 05:43AM

Re: Permanent redirection with regex after moving blog

Igor Sysoev August 13, 2009 06:20AM

Re: Permanent redirection with regex after moving blog

Marcus Clyne August 13, 2009 09:05AM

Re: Permanent redirection with regex after moving blog

Igor Sysoev August 13, 2009 09:50AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 281
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready