.htaccess to prevent hot linking with exclusions

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

.htaccess to prevent hot linking with exclusions

Post by brolly »

I would like to find out how can I exclude the w3c css validator (http://jigsaw.w3.org/css-validator/vali ... ysite.com/) from my hotlink bans. As you can see I placed w3\.org but it still is banned. Why ?

Also, I would like to allow google and yahoo to crawl my css and js files. But is this a user-agent issue or is it a referer issue ? If so, can I mix referer issues and user-agent issues in the follow code ?

I am also open to other suggestions (adding more lines to the following code) ...

Code: Select all

RewriteEngine on

RewriteCond %{HTTP_REFERER} !mysite\.com [NC]
RewriteCond %{HTTP_REFERER} !w3\.org [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]
RewriteRule \.(jpg|jpeg|gif|php|css|js)$ - [NC,F,L]
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: .htaccess to prevent hot linking with exclusions

Post by Roja »

brolly wrote:I would like to find out how can I exclude the w3c css validator (http://jigsaw.w3.org/css-validator/vali ... ysite.com/) from my hotlink bans. As you can see I placed w3\.org but it still is banned. Why ?
Why would you want to do so? People can still use the Firefox Web Developer plugin by using the "Send local CSS to Validator" function, so its not preventing validation.

Further, validation of your css is a GOOD thing, not a bad thing. If you've got errors in your css, why don't you ask for help fixing them?
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post by brolly »

I'm not sure I understood. I have a button on my site where if you click on it, that page's css file is validated but since my .htaccess file doesn't allow hot linking for css files, the validator does not work. So I would like to ban access to css files to everybody except the w3c validator.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Are you sure you want to do that :roll: You site might not look very good. The Validator can display the css anyway I believe.
sheila
Forum Commoner
Posts: 98
Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas

Post by sheila »

brolly wrote:I have a button on my site where if you click on it, that page's css file is validated but since my .htaccess file doesn't allow hot linking for css files, the validator does not work. So I would like to ban access to css files to everybody except the w3c validator.
I just directed the validator to one of my sites and in the log file there was no referrer ("-").
This was given for the User-Agent: "Jigsaw/2.2.5 W3C_CSS_Validator_JFouffa/2.0"
Try allowing "Jigsaw" as a user-agent and see what happens.
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post by brolly »

Does anyone know if google, yahoo or msn use referers or empty referers when crawling our sites like the css validator seems to do ?
sheila
Forum Commoner
Posts: 98
Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas

Post by sheila »

From looking at my logs it appears that Google visits have an empty referer. I'm going to guess that Yahoo and MSN do the same. It makes sense. They visit a site and get a list of links. Later they directly request those links and no referrer is involved.
Post Reply