Forum Moderators: phranque

Message Too Old, No Replies

restrict access by referring URL AND domain

restrict access by referring URL AND domain

         

TrishD

10:40 pm on Mar 15, 2004 (gmt 0)

10+ Year Member



I am an htaccess newbie, please help! Even the tutorials are too difficult for me to understand.

Here is what I want to do in English:

I am webmaster of an Air Force site. We are trying to move our users away from the site I maintain and encouraging them to use our new Portal. I'd like to restrict users from viewing my web site unless they are coming from an Air Force Portal URL. At the same time, I do not want to closeout access to those users outside the Air Force who need access but cannot get access through the Air Force Portal. Hope this makes sense.

So in English it would be:

Allow "https://www.afportal.mil" (referring URL)
Allow army.mil (domain)
Allow navy.mil (domain)
Allow .gov (domain)
Deny af.mil AND redirect to "https://www.afportal.mil"
Deny .com AND redirect to "http://www.afpublic.com/"

Could you help me to translate this into real code PLEASE!?

rogerdp

11:00 pm on Mar 15, 2004 (gmt 0)

10+ Year Member



To avoid an infinite loop if the browser has broken referers (browsers have settings to turn that off and other software, usually bundled with anti-virus software, can disable it too) you need to at least display a warning/notification page about why they are being redirected.

closed

3:45 am on Mar 17, 2004 (gmt 0)

10+ Year Member



If you read the Charter for this forum, you'll find this at the end:

Please do not post large blocks of code, or ask us to write your code for you

Take a stab at it first, then come back here and ask questions when you get stuck.

TrishD

1:56 pm on Mar 17, 2004 (gmt 0)

10+ Year Member



My sincere apologies for asking you all to write the code for me. I had no idea where to begin and I couldn't find anything similar in tutorials.

Since then I've found some code similar to what I am trying to do. I've tested out allowing from http_referer but when I test this, it denies access.

SetEnvIf Referer "^https://www7\.my\.af\.mil" allowit

<Limit GET>
Order deny,Allow
deny from all
Allow from allowit
</Limit>

The url I am testing from is [www7.my.af.mil...]

THANKS!

closed

3:30 pm on Mar 17, 2004 (gmt 0)

10+ Year Member



I don't really see anything wrong, except maybe for the fact that
deny
should start with a capital D.

Also, while I was looking for more info about the Limit directive, I found this in the Apache documentation [httpd.apache.org]:

A <LimitExcept> section should always be used in preference to a <Limit> section when restricting access, since a <LimitExcept> section provides protection against arbitrary methods.

TrishD

5:15 pm on Mar 17, 2004 (gmt 0)

10+ Year Member



Thanks! I will read the documentation.

In the meantime, I changed it to this (something else I found on the web) and it worked:

SetEnvIfNoCase Referer ".my\.af\.mil" allowit

<Files *>
order deny,allow
deny from af.mil
allow from env=allowit
allow from army.mil
allow from navy.mil
allow from .gov
</Files>

I dont understand a couple things...
1) what the difference is between <Files *> and <Limit>?
2) what does the "^" character do?
3) in what order do the commands get executed? I figured that if I put "deny from af.mil domain" first, it would deny anyone coming from ".my.af.mil" url as well, but it didnt.

So I am a little confused. I guess I will research this further.

Thanks.

closed

5:30 pm on Mar 17, 2004 (gmt 0)

10+ Year Member



Well, I'm sure you'll have a lot more questions in the near future, and I know that most of your questions can be answered by either looking through or reading these documents, so I'll refer you to them first:

Apache HTTP Server 2.0 directive quick reference [httpd.apache.org]
Regular expressions [etext.lib.virginia.edu]