Forum Moderators: phranque
RewriteEngine on
#ReWrites for Hotlink Protection
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://example.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.example.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://example2.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://example2.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.example2.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.example2.com$ [NC]
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ http://www.example.com/images/promo/88x31button02.jpg [R,NC]
#End Hotlink Protection
I'm not sure if the code is wrong somewhere or if there's an option I don't have turned on or what. I'm on a shared box so I don't have access to much other than .htaccess as far as configuration goes. Most of the code above was generated by cPanel, though I've tried a bunch of different examples from the net too and none of them worked.
Thanks for any insight.
RewriteEngine on
#Redirect for Hotlink Protection
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example2\.com [NC]
RewriteCond %{REQUEST_URI} !^/images/promo/88x31button02\.jpg$
RewriteRule \.(jpe?g¦gif¦png¦bmp)$ http://www.example.com/images/promo/88x31button02.jpg [NC,R=302,L]
#End Hotlink Protection
If you still have trouble, please post and explain what you see when 'it doesn't work'. You might consider installing the "Live HTTP Headers" extension to Firefox, so that you can watch the browser requests and server responses as the redirection takes place (or doesn't, as the case may be)... A very good basic tool for debugging.
Did you find that the "Options +FollowSymLinks" directive wasn't needed or caused a server error? If not, it should be included, just before the "RewriteEngine on" directive.
Replace all broken pipe "¦" characters in the code above with solid pipe characters before use; Posting on this forum modifies the pipe characters.
Jim
I was wondering if it had something to do with blocking the very image I was trying to show in the redirect. In the course of trying to get it to work cPanel deleted all my other redirects (non-www to www, index.php to / , etc), so I just used it to create the conditions for me out of frustration.
Needless to say I've created a backup copy of the .htaccess file and will never use cPanel to modify it again.
Thanks again.