I have a lot of hotlinked images. Which is fine but some do not exist anymore due to change in URL. Is it possible to display something like imageshack "image not found error" picture only when images are requested and they do not exist?

Right now I have 404 page but I'd still like to keep that.

I can put up a simple jpg/gif picture saying "Not found" and display that only when pictures are not found.

to be honest I don't know where to begin

my path can be anything from /level1/ to /level1/..../blah/oldpicture.jpg and most pictures are rendered by Gallery2 with url_rewrite so they actually go to php.

 location / {
                try_files $uri $uri /main.php?url=$1;
                #rewrite ^/(.+)$ /main.php?url=$1 last;

also I use this in php fpm config portion

fastcgi_intercept_errors on; # to support 404s for PHP files not found

I could try to this by coding but that is a second option.

2 Answers 2


You can change the error page based on the location. For example:

location ~ \.(png|jpg)$ {
    error_page 404 /404.png;

Perhaps add a location block to do a try_files on images and a rewrite from a named location on failure. Something like this (not tested):

location ~* \.(png|jpg|gif) {
    try_files $uri $uri/ @noimage;
location @noimage {
    rewrite ^ http://yousite.com/noimage.png;
location / {
    try_files $uri $uri/ /main.php?url=$1;
location \.php {
  • This will result in the incorrect status code being sent (200 instead of 404).
    – mgorven
    Commented Feb 22, 2013 at 18:46
  • Ah, yes, missed that in the original question.
    – chrskly
    Commented Feb 22, 2013 at 18:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .