# htaccess - allowing one denying all others

**URL:** <https://boards.straightdope.com/t/htaccess-allowing-one-denying-all-others/223299>\
**Category:** Factual Questions\
**Created:** [January 7, 2004, 10:27pm UTC](https://boards.straightdope.com/t/htaccess-allowing-one-denying-all-others/223299 "2004-01-07T22:27:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eats\_Crayons](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@Eats\_Crayons](https://boards.straightdope.com/u/Eats_Crayons)\
**Post date:** [January 7, 2004, 10:27pm UTC](https://boards.straightdope.com/t/htaccess-allowing-one-denying-all-others/223299/1 "2004-01-07T22:27:26Z")

</div>

Hm. In my Googling I haven’t been able to find a precise answer to this:

For anti-leeching, you can deny access to a specified linking URL, refusing access/traffic that is coming from links at the Evil URL.

Okay, cool. I’ve implemented that before.

What about the other way around, as in denying everyone _except_ the one linking URL?

Example/

If there was a section of my website that I visitors only to be able to access from links on my own site - no direct requests, no external links - to view the material you _must_ be coming through a link on _my_ page.

Sort of instead of: deny from env=BadReferrer

having something like: allow from env=GoodReferrer

Is this doable with htaccess or is it ridiculous and would cause too many failures depending on the browser?

Just curious.

---

<div class="post-metadata">

**Author:** ![Eleusis](https://avatars.discourse-cdn.com/v4/letter/e/f4b2a3/32.png) [@Eleusis](https://boards.straightdope.com/u/Eleusis)\
**Post date:** [January 7, 2004, 11:02pm UTC](https://boards.straightdope.com/t/htaccess-allowing-one-denying-all-others/223299/2 "2004-01-07T23:02:06Z")

</div>

RewriteEngine On  
RewriteCond %{HTTP\_REFERER} !^http://www.yourdomain.com [NC]  
RewriteCond %{HTTP\_REFERER} !^http://yourdomain.com [NC]  
RewriteRule /\* [http://www.yourdomain.com](http://www.yourdomain.com) [R,L]  
This will redirect any traffic not coming from your domain to your front page

---

<div class="post-metadata">

**Author:** ![Eats\_Crayons](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@Eats\_Crayons](https://boards.straightdope.com/u/Eats_Crayons)\
**Post date:** [January 7, 2004, 11:42pm UTC](https://boards.straightdope.com/t/htaccess-allowing-one-denying-all-others/223299/3 "2004-01-07T23:42:50Z")

</div>

Interesting. So this also prevents direct request (typing the address in the location bar) because it restricts the access to the one referrer only?

Very cool. I didn’t expect it to be so easy. I thought it might boggle up some basic browser requests. Thanks!

I’m gonna make a dummy page and play with it a bit! I’m curious to know how it would affect things like streaming media and file downloads like PDFs.

I have no real practical need for it, but it’s good to know for future reference… In case I ever need to go top secret and be _007 Eats\_Bonds_.

Thanks again!

---

<div class="post-metadata">

**Author:** ![Cleophus](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@Cleophus](https://boards.straightdope.com/u/Cleophus)\
**Post date:** [January 8, 2004, 1:23am UTC](https://boards.straightdope.com/t/htaccess-allowing-one-denying-all-others/223299/4 "2004-01-08T01:23:25Z")

</div>

You should also know that not all browsers forward the HTTP referrer. Opera, for example, can be configured to disable it. Anonymizing software may also block it.

---

<div class="post-metadata">

**Author:** ![Eats\_Crayons](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@Eats\_Crayons](https://boards.straightdope.com/u/Eats_Crayons)\
**Post date:** [January 8, 2004, 1:13pm UTC](https://boards.straightdope.com/t/htaccess-allowing-one-denying-all-others/223299/5 "2004-01-08T13:13:58Z")

</div>

Thanks for the input.

That was the worry I voiced in my OP - that it might produce some kind of “bad request errors” of some kind depending on the browser. I’m also suspecting it could cause glitches that affect files that are accessed by another software program or fancy schmancy plug-ins like media players or PDF readers (not quite sure how those call on the file).

In any case, my work day is expcted to be slow, so I’ll goof with it to see what happens.

Thanks for the warning. Htaccess can be pretty cool, but alas it has very pesky limitations. Fun to play with though.
