rewrite scheme for url redirect

Antoine BONAVITA antoine_bonavita at
Thu Jan 27 12:27:48 MSK 2011

Hi Sevy,

I looked at your rewrite rule, created a similar setup (with nginx 0.8.53) 
and...the rewrite rule works as expected. I attach my setup (the conf file and 
the whole directory in tar.bz2).
The only thing I can think of at this point is that your NGINX was compiled 
without regex support (PCRE).

Feel free to send me your conf file.


----- Original Message ----
From: sevy <nginx-forum at>
To: nginx at
Sent: Wed, January 26, 2011 10:11:30 PM
Subject: rewrite scheme for url redirect

I'm going crazy with this since I can't get it working in any way...

I have a subdomain on a server, let's call it,
dedicated to serve images. Due to some bandwidth limitation i got a more
capable server so the webpages will remain on but the images
will be moved to

Since I had to change the names of images folders on the new server now
I need to rewrite the urls in order to fit my needs. Only the webserver
on runs NginX, so i need to do rewrite the original ruls
following a regular expression (regex) and do something like:

- The first and most logic rewrite scheme I tought about is:

rewrite ^/oldfolder/([0-9][0-9])([0-9][0-9])([0-9][0-9])_([0-9]).jpg$$1/$2/new_images/$1$2$3/$1$2$3_image_$4_large.jpg

permanent;But it didn't work (I really don't know why)

- The second way I tried out is:

location /oldfolder/([0-9][0-9])([0-9][0-9])([0-9][0-9])_([0-9]).jpg$ {
    rewrite ^$1/$2/new_images/$1$2$3/$1$2$3_image_$4_large.jpg

}And it didn't work either...

I tried this config too:

location ~ oldfolder/ {
  rewrite ^([0-9][0-9])([0-9][0-9])([0-9][0-9])_([0-9]).jpg$$1/$2/new_images/$1$2$3/$1$2$3_image_$4_large.jpg

}But with no luck...

After that I tried an old config cheme i used for another site (on the
same box) for a cdn config:

location ~ /oldfolder/([0-9][0-9])([0-9][0-9])([0-9][0-9])_([0-9]).jpg
  rewrite ^/(.*)$

}I've been triying in several ways but nginx keeps ignoring my rewrite
scheme redirecting to my default error image located at

Can anyone help me with this?

I'll write down my subdomain server config for your facility:

## ##

    server {
        listen       80;
        error_page  404;
        root   /home/sites/;
        }It's a very basic server config, that's why I can't understand
why nginx doesn't rewrite the images following such scheme...

Posted at Nginx Forum:,169853,169853#msg-169853

nginx mailing list
nginx at

-------------- next part --------------
A non-text attachment was scrubbed...
Name: img_rewrite.tar.bz2
Type: application/x-bzip
Size: 6962 bytes
Desc: not available
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginx.conf
Type: application/octet-stream
Size: 1285 bytes
Desc: not available
URL: <>

More information about the nginx mailing list