Show default image if requested one has not been found on server - htaccess level

Posted on 2011-10-04
Last Modified: 2012-05-12

I have a image hosting website, I do obviously allow hotlinking, my problem is that sometimes I need to remove some images for copyright infringement, etc. and this image has been already embed on some other websites, forums, etc. In this case instead of request image X square currently shows up. I need some htaccess level solution to show some default image in case if the requested one does not exist anymore.

Thanks for help
Question by:jhmplondon
    1 Comment
    LVL 16

    Accepted Solution

    Use the ErrorDocument (404) directive.

    If you want to limit the redirect to only those files that were blocked, you can use the <files> directive:

    <Files "originalimage.jpg">
    ErrorDocument 404 /errors/notfound.jpg

    Open in new window


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now