Web Hosting Talk







View Full Version : Newbie Question about .htaccess


lovendove
10-20-2001, 12:59 AM
Hi,

I have been in search of a .htaccess file that will disable hotlinking and is compatable with all browsers... for some reason the one I was using was blocking netscape browsers from loading my page properly. If I am in the wrong place to ask this, I am sorry...

~lissa

Chicken
10-20-2001, 01:32 AM
Repost of some theead, soewhere on the forum here...


Yay! I tried the last one of Félix's examples and it worked (Cobalt RaQ4r)


the following does work on a raq3i:

(3 examples)

# ----------- Anti Leach
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
RewriteRule .*\(gif|GIF|jpg|JPG)$ - [F]

#
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
RewriteRule .*\(gif|GIF|jpg|JPG)$ - [F]
RewriteEngine on

#
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
RewriteRule .*\(gif|GIF|jpg|JPG)$ http://www.domain.com [R]
__________________
Félix C.Courtemanche . webmaster@can-host.com
Co-Administrator . Can-Host Networks

lovendove
10-20-2001, 02:24 AM
Thanks for the speedy reply!

I tried all of them and not one prevented hotlinking for me. :bawling:

I wound up trying the script I had again because it seemed odd to me that none of the ones you posted worked. Since my file is working I am guessing the ones you posted didn't because of my host's equipment or something... (can you tell I am a newbie LOL).
In your post you mentioned raQ versions... could this be my problem or is it netscapes browser?

The following .htaccess works fine on IE but on netscape it shows broken links on index and messes up my JavaScript rollovers within other pages.

Here is the script I am using


_______________________

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://*domain.com* [NC]
RewriteRule /* http://www.domain.com/error403.htm [L,R]
_________________________

Its stopping hotlinking but if its not going to work on netscape whats the point:confused: Thanks again!

Chicken
10-20-2001, 10:43 AM
Hmmm, that is odd. I'm not too familiar with why/if a browser would cause this to fail. Is server side, but I suppose it is relying on the browser to some degree.

Just wondering if the file is flogged, did you upload it in ascii?

Quite odd... not sure what to tell ya', but maybe someone else knows more about this issue... ?

Just for kicks, post which RaQ you are using in case someone else has successfully gotten something to work.

lovendove
10-20-2001, 03:04 PM
Im uploading in ascii (using ws_ftp Pro so I have to add the .htaccess to the list of extensions accepting ascii...maybe there is a setting I am missing in my fp client???).

I have no idea what version of raQ my host has and I sent an email to support asking for that info.

Also is there any chmod that needs to be set for this file or the directory the .htaccess is in?

Chicken
10-20-2001, 07:35 PM
If it is only something that happens with different browsers, I don't think that could be it, but really I have no idea what is causing the problem.

lovendove
10-20-2001, 09:12 PM
I asked my host what version of raQ they were using and this was his response:

"We do not use RAQ servers. We use real IBM servers."

Again I an a newbie and this is my first attempt at .htaccess files etc. so I have no idea what is going on.

I thought maybe it was my JavaScript that was messing it up but even on pages without any Javascript netscape still shows broken links.... on other pages the rollovers are not working properly:confused:

Thanks for all your help. God willing, one day I will get this working:D

~lissa

getweb
10-21-2001, 12:24 AM
First, I would make sure your browsers are sending the "HTTP_REFERER" header in the first place. Visit this URL with the browsers you want to test:

http://www.research.att.com/~mjm/cgi-bin/cgienv/form

It will list the headers your browser is sending... HTTP_REFERER should be one of them. If it is not there, it explains the problem. You simply will not be able to restrict hotlinking for that browser.

From there, it's up to you. You can either deny unless allowed, or allow unless denied. :) The code you provided denies access unless specifically allowed - so if the header is not present, it will deny access.

This code below will restrict access if the header is present, but if it is not there, it will go ahead and allow it. This will keep you from getting broken images if the browser does not send the header at all.

========
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://*domain.com* [NC]
RewriteRule /* http://www.domain.com/error403.htm [L,R]
========

I haven't *tested* that, but basically what we're saying is "If the Referrer is NOT empty, and is NOT from my domain, then go 403 on their ---."

Try that...
-Adam

P.S. My issues with HTTP_REFERER vs. HTTP_REFERRER can best be summed up in a dictionary.com entry:
http://www.dictionary.com/cgi-bin/dict.pl?term=referer

getweb
10-21-2001, 12:38 AM
Oh dear! Look what I have done! I bet the above code prevents anybody from linking to your site at all! Try this instead:

========
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://.*domain.com.* [NC]
RewriteRule .*\.(gif|GIF|jpg|JPG)$ http://www.domain.com/error403.htm [L,R]
========

This code is tested! I made it work finally. :-) My research had led me to incorrect references...

You can tell I'm a Jr. Guru Wannabe, eh?

lovendove
10-21-2001, 03:03 PM
THANK YOU SOOO MUCH!!!

Its working now.

So on netscape it ignores the .htaccess right? OH who cares LOL it stopped hotlinking and is working on netscape:D

I went to that link and the http referer wasn't empty. I don't know why it was messing up but its all good now!

God Bless and thank you all for the help!

~lissa