htaccess - redirect all image names to default.jpg?

Discussion in 'Apache' started by Kerosene, Jul 9, 2009.

  1. #1
    Is it possible to use htaccess to redirect all queries for non existent images to a default.jpg?

    What I want to do is use keyword rich image names in my code, but display my default.jpg instead.

    e.g my html says:
    <img src="purple-widgets-for-sale.jpg" />

    But since that image doesn't really exist, it pulls in default.jpg instead.

    I hope this makes sense. And I hope it's possible somehow.
     
    Kerosene, Jul 9, 2009 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Try adding this to the .htaccess file of some directory and all the files behind that directory will be affected:

    <FilesMatch "\.(jpg|jpeg|png|gif|JPG|JPEG|GIF|PNG)">
    ErrorDocument 404 path_to_your_default_jpg
    </FilesMatch>

    Value example for path_to_your_default_jpg: "/pic/default.jpg"
     
    ajsa52, Jul 10, 2009 IP
    thuankkk and qardinal like this.