Forum Moderators: phranque
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example\.co\.uk [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example\.co\.uk [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example2\.co\.uk [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example2\.co\.uk [NC]
RewriteRule \.(gif¦jpg¦jpe?g¦bmp)$ - [F,NC,L]
[edited by: jdMorgan at 5:18 pm (utc) on Jan. 20, 2004]
[edit reason] Removed specifics per TOS [/edit]
ErrorDocument 404 /404error.html
Options -Indexes
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example.com [NC]
RewriteRule \.(gif¦jpe?g)$ /loser.$1 [L]
Please let me know what I'm doing wrong! Thank you so much for your help.
[edited by: jdMorgan at 5:18 pm (utc) on Jan. 20, 2004]
[edit reason] Removed specifics per TOS [/edit]
Welcome to WebmasterWorld [webmasterworld.com]!
Many server configurations will require you to have Options +FollowSymLinks before any mod_rewrite directives. On others it is not needed, and on still others it can cause a 500-Server error. You must test to find out which applies.
You must have "RewriteEngine on" before any other directive processed by mod_rewrite.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.co\.uk [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example2\.co\.uk [NC]
RewriteRule \.(gif¦jpg¦jpe?g¦bmp)$ - [NC,F]
RewriteRule \.(gif¦jpe?g)$ /loser.$1 [NC,L]
You must edit the code above and change the broken pipe "¦" characters to solid pipes characters - usually SHIFT - \ on a standard (U.S.) keyboard.
The [L] flag used with [F] is redundant; The combinations shown above are sufficient.
When testing, be sure to flush your browser cache (Temporary Internet Files) between requests. Also, use Shift-Reload or Control-Reload (whichever applies to your browser) to force a complete page reload from the server. Otherwise, if the image is cached, it will not be requested from your server. And if it's not requested from your server, then your code can have no effect.
Both of your code samples allow access using a blank referrer. This is almost always required to avoid massive problems with visitors who connect (knowingly or unknowingly) through corporate or ISP firewalls, caches and/or proxies which often block rererrer information. However, it will allow direct type-in-the-address-bar and right-click browser access, and there's nothing that can be done about that without significantly more complicated measures being taken.
The subjects of hotlinking and blank referrers have been much-discussed here. For more information, try a site search for "hotlinking" and "unreliable HTTP_REFERER" and similar phrases.
Jim
Would there be any effect on the fact they didn't put a <space> between these:
REFERER} and!
--
Note: For some reason, the edit of the post doesn't produce a space between }! on the forum.
This is what my htaccess file looks like now:
ErrorDocument 404 /404error.html
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?graphicsmuse\.com [NC]
RewriteRule \.(gif¦jpg¦jpe?g¦bmp)$ - [NC,F]
Unfortunately, it still does not work and, for the life of me, I can't figure out why. My domain host does support mod_rewrite and I've uploaded it as an ASCII file and it's CHMOD as 644 or -rw-r--r-- I've also made sure the ¦ are right.
It's in my root directory where my index.php file is, in case that makes any difference. Should I place it instead in the folder that contains the images I do not wish to be hotlinked to?
Please, if anyone can figure this out for me, I'd be very grateful! Thank you!
my file now looks like
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.co\.uk [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example2\.co\.uk [NC]
RewriteRule \.(gif¦jpg¦jpe?g¦bmp)$ - [NC,F]
[edited by: jdMorgan at 6:10 am (utc) on Jan. 27, 2005]
[edit reason] Removed specifics per TOS. [/edit]
Also, the code you are using allows blank referrers (as it must to avoid major customer-service complaints) and therefore, direct-type-in image URLs will never be blocked, so be aware of this during testing.
If the above does not help, then perhaps your server does not support mod_rewrite at all. :(
Jim