need rewrite help

Igor Sysoev igor at sysoev.ru
Wed Sep 21 05:01:44 UTC 2011


On Wed, Sep 21, 2011 at 04:57:10AM +0700, Denis F. Latypoff wrote:
> 21.09.2011, 04:50, "António P. P. Almeida" <appa at perusio.net>:
> > On 20 Set 2011 22h38 WEST, nginx-forum at nginx.us wrote:
> >
> >>  Hi,
> >>
> >>  please help me to rewrite this mod_rewrite rule:
> >>  RewriteRule    (img/(.+))$ webroot/$1     [L]
> >
> > Try:
> >
> > location ^~ /img/ {
> >     location ~* /img/(.+)$ {
> >        return 301 /webroot/$1;
> >    }
> > }
> >
> > Or 302 if you want it to be temporary.
> 
> There is no [R] flag in the rewrite rule, so it should be internal redirect
> 
> location /img/ {
>     alias /path/to/webroot/;
> }

I think $1 in RewriteRule is a whole "img/...":

$ pcretest 
PCRE version 7.9 2009-04-11

  re> #(img/(.+))$#
data> img/qqq
 0: img/qqq
 1: img/qqq
 2: qqq
data> ^D

So it should be "root":

location /img/ {
    root  /path/to/webroot/;
}


-- 
Igor Sysoev



More information about the nginx mailing list