Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 4 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
add comment

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 {
    ...
}
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
add comment

Your Answer

 
discard

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.