Forum Moderators: phranque

Message Too Old, No Replies

where to put hotlinking protection in my .htaccess file

         

riospace

1:40 pm on Oct 25, 2006 (gmt 0)

10+ Year Member



My .htaccess file currently looks like this:

DirectoryIndex index.php index.html index.htm

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?Šphp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?Šphp)$ [www\.example\.com...] [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ [www\.example\.com...] [R=301,L]

The above code makes my hotlink protection panel in cPanel act weird so I am just going to avoid the cPanel hotlink protection generator and just add my own code directly into .htaccess. I want to add the following code and am not sure where I should place it in my .htaccess file above. Also, is there a better code to use that will not block any image search engines and is there a suggested list of image search engines to not block?

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http(s)?://(www\.)?yourdomain.com [NC]
RewriteCond %{HTTP_REFERER}!^http(s)?://(www\.)?live.com [NC]
RewriteCond %{HTTP_REFERER}!^http(s)?://(www\.)?msn.com [NC]
RewriteCond %{HTTP_REFERER}!^http(s)?://(www\.)?google.com [NC]
RewriteCond %{HTTP_REFERER}!^http(s)?://(www\.)?yahoo.com [NC]
RewriteRule \.(jpg¦jpeg¦png¦gif)$ - [NC,F,L]

jdMorgan

2:58 am on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I usually put the IP address-, user-agent-, and hotlink- blocking code first, on the premise that you don't want to waste your server's time redirecting or rewriting requests from unwelcome visitors.

Not knowing where your site is located, what kind of site it is, or how 'visible' or popular it is on the Web, I can't recommend any particular list of referrers to include or exclude. Keep an eye on your log files for a few weeks, and you'll soon know. Or review your past logs for image request referrers if you prefer.

Jim

riospace

12:18 pm on Oct 26, 2006 (gmt 0)

10+ Year Member



When I added my hotlink protection I got a server error for the site. In my error logs I found the following error repeated:

[Thu Oct 26 06:21:48 2006] [alert] [client .htaccess: RewriteCond: bad argument line '%{HTTP_REFERER}!^$'\n

jdMorgan

1:56 pm on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like you're missing the required space between "}" and "!"

Jim