Forum Moderators: phranque
I've recently been trying to add a .hta to my website, after a lot of hotlinking to my content. I would like to, if possible ban other sites apart from my own from hotlinking to vidoes, pictures, audio clips and any other media as it's draining my bandwidth.
Here's the .hta I tried to use -
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^[http好ttp].*$
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example1.com/.*$ [NC]
RewriteRule .*\.(gif夸pg夸peg在mp安av安mv屹ip妃p3安av)$ [example1.com...] [R,L]
And another I tried using -
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^[http好ttp].*$
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example1.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.example1.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example1.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.hosting.example2.net/~admin32/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example1.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.example1.com/index.php/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example1.com/index.php(/)?.*$ [NC]
RewriteRule .*\.(gif夸pg夸peg匡PG匡pg)$ [google.com...] [R,L]
(The google redirect image is just an example. Both these don't work for me. They actually block my site from using the images.
Any help would be greatly apreciated. ^_^
[edited by: jdMorgan at 5:11 pm (utc) on Feb. 11, 2004]
[edit reason] No personal URLs, please. See TOS. [/edit]
Welcome to WebmasterWorld [webmasterworld.com]!
I'd suggest you keep it simple, and start with something like this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example1\.com [NC]
RewriteCond %{HTTP_REFERER}!^http://www\.hosting\.example2\.net/~admin32 [NC]
RewriteRule \.(gif夸pe?g在mp安av安mv屹ip妃p3)$ /nohotlink.jpg [L]
RewriteCond %{HTTP_REFERER} ^[http好ttp] RewriteCond %{HTTP_REFERER} ^(http好ttp) There is another layer of "problem" here, and that is that browsers cannot handle a redirect from one file-type to another unrelated filetype, such as from zip to .jpg - this will not work as expected. I'd suggest:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example1\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://www\.hosting\.example2\.net/~admin32 [NC]
RewriteRule \.(gif夸pe?g在mp)$ /nohotlink.$1 [L]
#
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example1\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://www\.hosting\.example2\.net/~admin32 [NC]
RewriteRule \.(wav安mv屹ip妃p3)$ - [F]
RewriteRule \.(gif夸pe?g在mp安av安mv屹ip妃p3)$ - [F] You may or may not need that first Options line. If you don't need it, it may cause a server error. However, mod_rewrite won't work if you do need it and don't have it. If you don't have access to the server config file httpd.conf, the only way to find out is to test it.
Check your server error log while testing this code - It will often tell you what and where the problem is.
All broken pipe "¦" characters in the code above must be replaced with solid pipe characters from your keyboard before use.
Jim
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example1\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://www\.hosting\.example2\.net/~admin32 [NC]
RewriteRule \.(gif夸pe?g在mp)$ /nohotlink.$1 [L]
#
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example1\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://www\.hosting\.example2\.net/~admin32 [NC]
RewriteRule \.(wav安mv屹ip妃p3)$ - [F]
It was partially successful. The .hta blocked the audio and video clips from being hotlinked but the .hta still blocks my own site from linking to the images and some images don't appear when the .hta is in place.
Any ideas?
[edited by: jdMorgan at 8:02 pm (utc) on Feb. 13, 2004]
[edit reason] Examplified URLs. [/edit]
Another thing I should note here is that when you are testing .htaccess code, you must flush your browser cache before each test of new .htaccess code. Otherwise, your browser will simply display whatever it cached the last time you made that request - including 403 responses.
Jim
I did clear my cache beforehand but still to no avail.
Here's some information I collected from a header sent and recieved for one of the images on my site -
http://www.example1.com/pics/banners/Earshotmusic.jpg
GET /pics/banners/Earshotmusic.jpg HTTP/1.1
Host: www.boavid.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007 Firebird/0.7
Accept: image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.example1.com/gallery2/propercrimbogallery.php
HTTP/1.x 403 Forbidden
Date: Mon, 02 Feb 2004 20:57:00 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_jk/1.2.0 mod_perl/1.26 PHP/4.3.3 FrontPage/5.0.2 mod_ssl/2.8.12 OpenSSL/0.9.6b
Keep-Alive: timeout=15, max=81
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1
Any help would be much apreciated.
[edited by: jdMorgan at 8:04 pm (utc) on Feb. 13, 2004]
[edit reason] Examplified URLs. Please see TOS. [/edit]
The only thing that stands out is your comment that "some images" don't show. If this is the case, then you need to carefully examine the logs to see why the request failed. What server response code did you get? What was the exact requested hostname when the image failed to show up?
There's no real magic here, and the high-level answer is that your legitimate request is being blocked because the rewriterules don't see it as legitimate -- the referrer is not being recognized as one of your valid referrers. So the question is, "Why not?"
I'm sort of hoping someone else will spot something I've missed here, but if not, you are going to have to dig into the server access and error logs to figure this out.
Jim