Forum Moderators: phranque
RewriteEngine on
# Prevent hot-linking
# Allow linking from my own site
RewriteCond %{HTTP_REFERER}!^http://mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://mysite.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com$ [NC]
# But not allow hot-linking to any images in the image_folder
RewriteCond %{REQUEST_URI}!^/image_folder/.*$ [NC]
# Re-direct any links to image files to another site
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ [site-to-redirect-to.com...] [R,NC,L]
I’m trying to apply the Rewrite rule in the .htaccess to affect the rest of my site, not just the home page. Will this work?
RewriteEngine on
# Prevent hot-linking
# Allow linking from my own site
RewriteCond %{HTTP_REFERER}!^http://mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://mysite.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://mysite.com/page2/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://mysite.com/page2$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com/page2/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com/page2$ [NC]
RewriteCond %{HTTP_REFERER}!^http://mysite.com/page3/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://mysite.com/page3$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com/page3/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com/page3$ [NC]
etc…
# But not allow hot-linking to any images in the image_folder
RewriteCond %{REQUEST_URI}!^/image_folder/.*$ [NC]
RewriteCond %{REQUEST_URI}!^/image_folder2/.*$ [NC]
RewriteCond %{REQUEST_URI}!^/image_folder3/.*$ [NC]
etc…
# Re-direct any links to image files to another site
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ [site-to-redirect-to.com...] [R,NC,L]
I have a total of seven pages and image folders that I would like to add, I would also like to mention that [mysite.com...] and [mysite.com...] etc... ends with a .htm like this [mysite.com...] Does that make a difference?
RewriteEngine on
# Prevent hot-linking
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com [NC]
# Re-direct any links to image files to another site
RewriteRule \.(jpe?g¦gif¦png¦bmp)$ http://www.site-to-redirect-to.com/ [R,NC,L]
The fact is that you cannot rely on the HTTP Referer header to be present or to be correct. It will be blocked without the knowledge of many visitors, and is easy enough to spoof as well.
Therefore, most Webmasters find that it is necessary to allow blank referrers as a trade-off between protecting their site and not having their site appear to be broken to the 10% or so of their visitors who don't provide a referrer.
Also, it is a waste of internet resources to redirect hotlinkers elsewhere -- You are using everyone's network bandwidth and simply passing the problem along to another Webmaster to suffer with. I recommend that as a citizen of the Web, you simply block the access with a 403-Forbidden response and be done with it.
RewriteEngine on
# If HTTP_REFERER header is present (non-blank)
RewriteCond %{HTTP_REFERER} .
# and if referrer is NOT my own site
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite\.com [NC]
# Forbid access
RewriteRule \.(jpe?g¦gif¦png¦bmp)$ - [F] [NC,L]
Jim
[edited by: jdMorgan at 5:57 pm (utc) on Nov. 19, 2006]