rewrite scheme for url redirect

António P. P. Almeida appa at
Thu Jan 27 01:07:45 MSK 2011

On 26 Jan 2011 21h11 WET, nginx-forum at wrote:

> 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:
> --rewrite-->
> - 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$
> permanent

On config try this:

location /oldfolder {
   rewrite ^/oldfolder/(\d{2})(\d{2})(\d{2})_(\d)\.jpg$$1/$2/new_images/$1$2$3/$1$2$3_image_$4_large.jpg? permanent;

--- appa

More information about the nginx mailing list