Forum Moderators: phranque

Message Too Old, No Replies

.htaccess - only hotlink 1 page?

         

xxshadowxx

6:28 pm on Mar 10, 2007 (gmt 0)

10+ Year Member



How would I only make hotlink protection available for only 1 page?


RewriteEngine on
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example.net(/)?.*$ [NC]
RewriteRule .*\.(gif¦jpg¦jpeg¦bmp¦html¦php¦phtml¦php3¦htm)$ http://example.net/error.html [R,NC]

It goes to error.html, which is also protected by htaccess, then goes to error.html again, and again...

Any solution would be helpful.

[edited by: jatar_k at 6:42 pm (utc) on Mar. 10, 2007]
[edit reason] examplified [/edit]

jdMorgan

7:27 pm on Mar 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Simply exclude error.html from being redirected:

RewriteEngine on
#
RewriteCond %{REQUEST_URI} !^error\.html$
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.net [NC]
RewriteRule \.(gif¦jpe?g¦bmp¦html?¦php¦phtml¦php3)$ http://example.net/error.html [R=302,NC]

Note the other cleanups and optimizations -- there was a lot of CPU-wasting junk in there.

The second new RewriteCond allows requests with a blank referrer header, and is recommended. Although it opens a "hole" in the hotlink protection, it will prevent you from having massive problems with blocking users sitting behind corporate or ISP proxies, e.g. EarthLink and AOL. These requests will not have a referrer, and the visitors will see your site as broken and therefore low-quality/untrustable.

Replace all broken pipe "¦" characters in the code above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim