Having trouble with the PCRE syntax

Igor Sysoev igor at sysoev.ru
Fri Mar 11 20:47:07 MSK 2011


On Mar 11, 2011, at 20:33 , Maxim Dounin wrote:

> Correct regexp-based solution would be
> 
>    location ~* ^/(?:forum|forums|board)(?:/|$) {
>        rewrite ^/[^/]*/*(.*) http://forum.my_domain.com/$2 permanent;
>    }
> 
> But recommended way is to avoid regexp-based solutions without 
> real need.  It's much simplier and much more scalable to write 
> configuration with normal static locations, i.e.
> 
>    location = /forum {
>        rewrite ^ http://forum.my_domain.com/ permanent;
>    }
>    location /forum/ {
>        rewrite ^/forum/(.*) http://forum.my_domain.com/$1 permanent;
>    }
>    location = /board {
>        rewrite ^ http://forum.my_domain.com/ permanent;
>    }
>    location /board/ {
>        rewrite ^/board/(.*) http://forum.my_domain.com/$1 permanent;
>    }
> 
> This way you'll save yourself a headache.

[ when configuration will eventually grow.
  And it will certainly grow eventually. ]

> As a side effect - it's 
> faster.
> 
> Maxim Dounin


--
Igor Sysoev
http://sysoev.ru/en/




More information about the nginx mailing list