I have the following URLs:

  • www.example.com/data/images/13122013-002_IM1621.jpg
  • www.example.com/data/images/13122013-002_IM1622.jpg
  • www.example.com/data/images/13122013-002_IM1622.jpg

On the file system images are named:

  • 1621.jpg
  • 1622.jpg
  • 1623.jpg

What is the correct rewrite rule? I've tried:

location / {
rewrite ^/.*_IM(.*)$ /data/images/$1;

But I keep receiving a 404 error.


Change location to location ~ \.jpg$ (or to more specific path, but regex) and check.

Note that regex locations will be used in the order in config, not by "best match"

"/" might not work because it matches any request it will be used as a last resort (probably - we don't see your config)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.