Nginx rewrite URL only if file exists

Posted by Jose Fernandez on Server Fault See other posts from Server Fault or by Jose Fernandez
Published on 2010-03-14T08:49:13Z Indexed on 2010/03/14 8:55 UTC
Read the original article Hit count: 385

Filed under:
|
|

I need to write a rewrite rule for Nginx so that if a user tries to go to an old image url:

/images/path/to/image.png

and the file doesnt exist, try to redirect to:

/website_images/path/to/image.png

ONLY if the image exists in the new URL, otherwise continue with the 404. The version of Nginx on our host doesn't have try_files yet.

© Server Fault or respective owner

Related posts about nginx

Related posts about rewrite