nginx rewrite

Igor Sysoev igor at sysoev.ru
Mon May 2 22:57:16 MSD 2011


On Mon, May 02, 2011 at 08:48:50PM +0200, Yanxin Z. wrote:
> Hello Igor Sysoev,
> Thank you for your help.
> 
> You suggestion is great, but my problem is a little bit complicated.
> 
> The image name is flexible, can be from 0.jpg to 23456.jpg, we organize 
> the image files into folders, whose name is the number divide by 1000. 
> For example, the folder 100 saves the file 100000.jpg to 100999.jpg.
> 
> Both the folder and file name are flexible in my case.
> 
> Do you have any suggestion on it?

location /img/ {

    location ~ ^/img/(\d)(\.jpg)$ {
        alias   /path/to/img/0$1/$1$2;
    }

    location ~ ^/img/(\d\d)(\d*\.jpg)$ {
        alias   /path/to/img/$1/$1$2;
    }

    return 404;
}


-- 
Igor Sysoev



More information about the nginx mailing list