View Full Version : .htaccess and site resources

03-22-2006, 04:45 PM
Shawn, this one is for you!

During a recent browsing session, I came across this thread :
http://forums.westhost.com/showthread.php?t=7648 which refers to using .htaccess to prevent hotlinking of images from a site.

In this thread, Shawn, you made mention of having an example of how using .htaccess would work and that included this link: http://wildjokerdesign.com/phpBB2/viewtopic.php?t=47 which now, unfortunately gives me a 404 error.

Can you give me a quick rundown of what you did?



03-22-2006, 08:58 PM
Sure Joss no problem! The post is there I still I just changed the directory of my board. Best I post it here anyway since I am not sure if I am going to keep the board up anymore. :) Below is a cut and past from the orginal.

Many folks want to keep others from linking to thier images from other sites. This can be accomplished by placeing a .htaccess file in the directory where you have your images. It would look something like this.

Rewriteengine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://domain.com/alternate.gif [R,NC]

The code is five lines only in case it does not display correctly on your computer. Each line starts with Rewrite. This well work on WestHost servers but if you are with another hosting company it may not work if they do not allow you to us Rewrite or .htaccess files.

What this well do is instead of showing the image they had wanted to from your server it well display the alternate.gif that you have in your root www directory. This file must not be in that directory but in one below it where have your images for the rest of your site. You would replace domain with your domain name and the last line is the url path to the image you want to show.

You can allow other domains to use images from your site if would like by simply adding them in using the format of lines 4 and 5.

P.S. If you happen to run across other old links to my board that do not work just replace phpBB2 with board as the directory and you should be able to find them.