rewrite rule to 2 subdirectory from filename?

Elena Zwetkow ezwetkow at gmx.de
Wed Jul 18 23:06:51 UTC 2012


Hello,

a short question about nginx rewrite function. Is it possible
to rewrite a url like:

http://domain.com/486ab6c88fd112a89ccgdwd04a3d8275:8d27ce:1.jpg

to a path like:

/media/48/6a/486ab6c88fd112a89cc4d9d04a3d8275:8d27ce:1.jpg

i will use the first 4 characters of my filename as 2 subdirectories. This was my test, but works not ...

location / {
  rewrite "^/([a-z0-9] {2})([a-z0-9] {2})([a-z0-9]+)$" /media/$1/$2/$1$2$3
}

Is there a way i can debug such rewrite rules?

Thanks so much.

Elena




More information about the nginx mailing list