Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 8 down vote accepted

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

location ~ \.(png|jpg)$ {
    error_page 404 /404.png;
share|improve this answer

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 ^;
location / {
    try_files $uri $uri/ /main.php?url=$1;
location \.php {
share|improve this answer
This will result in the incorrect status code being sent (200 instead of 404). – mgorven Feb 22 '13 at 18:46
Ah, yes, missed that in the original question. – chrskly Feb 22 '13 at 18:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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