cancel
Showing results for 
Search instead for 
Did you mean: 

.htaccess Question

thejudge
Rising Star
Posts: 624
Thanks: 10
Registered: ‎01-08-2007

.htaccess Question

I have the following in the .htaccess on my webspace, intended to prevent hotlinking:
Quote
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?<domain name>.*$ [NC]
RewriteRule \.(gif|jpg|png|wmv)$ -

People are telling me that this is stopping them even from viewing images on my webspace if I provide them with a direct link to the image, e.g. http://www.thejudge.me.uk/imagebank/photos/kw_catalogue_me.jpg.
What do I need to amend in the .htaccess to stop that from happening? Or am I missing something simple here?
5 REPLIES 5
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: .htaccess Question

How do you provide the direct link to those you invite to view the image? If it's in a forum post such as here, then the forum site will be sent as the referrer, and the rule blocks access. In this case the forum site would have to be excluded by a negative condition like that for <domain name>, or some other property needs to be checked,.
If invitees copied the link into their browser's address bar (or clicked a link in an email) the referrer would be empty, and the first exception allows that.
David
thejudge
Rising Star
Posts: 624
Thanks: 10
Registered: ‎01-08-2007

Re: .htaccess Question

In the cases in question, the link has been a hyperlink in a forum post. As it's a forum where I'm a mod, I might as well exclude that as well.
What would the syntax be for that? Would it be:
RewriteCond %{HTTP_REFERER} !^http://(www\.)?<forum domain name>.*$ [NC]
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: .htaccess Question

That's the idea, but it depends whether the subdomain is www, and whether that is optional. For example, for a link posted in the Community forum the exclusion condition would be
RewriteCond %{HTTP_REFERER} !^http://community\.plus\.net/forum/.*$ [NC]

That would allow links from forum posts but exclude them from elsewhere on the site - up to you whether you want to be that specific.
David
thejudge
Rising Star
Posts: 624
Thanks: 10
Registered: ‎01-08-2007

Re: .htaccess Question

Tried that, but it's still blocking the link from the forum I posted it in.
Is there actually a combination of code which will prevent hotlinking but allow viewing?
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: .htaccess Question

As far as I'm aware the server can't tell the difference between a reference to display within a page (hotlink) and a clicked link to display in the browser (view).
However I've just tried this from Community to a jpg image on my site and the exception posted above worked OK. I got 403 forbidden without the Community condition in .htaccess, but the image displayed OK when I added it.
HTTP_REFERER contained
http://community.plus.net/forum/index.php?action=post;topic=106986.0;num_replies=4

Are you sure you didn't make a typo?
David