htaccess / hotlink prevention / nowww!

htaccess / hotlink prevention / nowww!

Posted by: dwr
Posted on: 2007-11-19 22:04:00

From the amazing Dreamhost Wiki, I find that I can put this:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www.)?example.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .(jpe?g|gif|png)$ - [F]

into my htaccess to prevent hotlinking. What I'd like to know is, does it make any difference if you are using all non www sites (the example.com above has the www) and if so what should be changed?

Re: htaccess / hotlink prevention / nowww!

Posted by: Lensman
Posted on: 2007-11-19 23:00:00

(www.)?

? is 0 or 1 of the preceding text.
(text) groups the text together
char escapes the ., which is a special character

So that part of your regular expression says that there may or may not be a www. between the "http://" and the "example.com" part of the url.

Re: htaccess / hotlink prevention / nowww!

Posted by: dwr
Posted on: 2007-11-19 23:21:00

Ahhh... once again, thank you Lensman!

Now if only there were a way to block ALL of China from one of my sites! Why they index me into crappy and downright strange portals over there I just don't understand.


Re: htaccess / hotlink prevention / nowww!

Posted by: rlparker
Posted on: 2007-11-20 00:06:00

In reply to:

Now if only there were a way to block ALL of China from one of my sites! Why they index me into crappy and downright strange portals over there I just don't understand.


Maybe they just *love* all your content and want "all your pages are belong to us" wink

-rlparker

Tags: http refererhtaccessmark twainhotlinkingrewriterulehotlinkjpedreamhostpngpausewikiprevention