Forum Moderators: phranque
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteMap LeechProtect prg:/usr/local/cpanel/bin/leechprotect
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mysite.com/.*$ [NC]
RewriteRule .*\.(gif¦GIF¦jpg¦JPG¦jpeg¦JPEG¦png¦PNG)$ [mysite.com...] [R]
</IfModule>
However, that rule can be re-coded in a much more efficient way, and you can save bandwidth by denying the request instead of trying to redirect image requests to an HTML page (which won't work most of the time):
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com
RewriteRule \.(gif¦jpe?g¦png)$ - [NC,F]
When testing, be aware that if you successfully load an image, then that image will be stored in your browser cache and will be displayed from your cache until that cache entry expires or is removed. Therefore, it's important when testing anti-hotlinking code that you completely flush your browser cache (delete Temporary Internet Files in IE) before doing another 'test'.
So the procedure must be:
Jim
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteMap LeechProtect prg:/usr/local/cpanel/bin/leechprotect
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com
RewriteRule \.(gif¦jpe?g¦png)$ - [NC,F]
</IfModule>
Here's some more information as it concerns document root.
DocumentRoot /home/servername/public_html
<Directory "/home/servername/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
And I have about 5 other sites on the server. Thanks.
If that doesn't help, please tell us how the code "doesn't work" -- Specifics of your test, your results, and how they differed from your expectations, as well as any entries from your server error log, might be most helpful.
Jim