Allow/Deny directive & multiple IPs?

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
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Allow/Deny directive & multiple IPs?

Post by tomfra »

Let's say I have something like this in my .htaccess:

Code: Select all

Order Deny,Allow
allow from 123.123.123.123
allow from 124.125.126.127
Deny from all
Is there a way I could avoid repeating the "allow from" (or "deny from") part for each of the IPs? Or is there a way I could supply the IPs from an external file?

Thanks!

Tomas
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

What about the Include directive? Btw, don't forget this configuration file is only read when apache is starts/(re)loads...
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Post by tomfra »

The Include directive can apparently be used for the server-wide config only. I need something that can be used through .htaccess.

Tomas
Last edited by tomfra on Fri Feb 04, 2005 3:49 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

write a script to handle the file's formatting and whatnot?
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Post by tomfra »

Of course, I can write a PHP script that will create the .htaccess file in the right format but there can be many IPs and if the "allow from" does not have to be repeated on each line, I could save some bytes. It may be totally unimportant but...

Tomas
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Post by tomfra »

Ok folks, still looking for a solution to this problem... I am sure there is one, right?

I wrote a php script that does the proper formatting but if there are many IPs and you need to repeat the "allow from" part for each of them, it does add a lot of kilobytes to the .htaccess file which I want to avoid if possible.

So the question once again is: Is it possible to include an external file with IPs (one IP per line) from within .htaccess and tell Apache to share the same (allow or deny) directive for all of them?

Thanks for any ideas!

Tomas
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

i'm still wondering if there is a problem....

i see that you can buy a hd with 40Gb for 40€ => 1€/1Gb.
don't see how those few bytes can be worth the effort.... (and that is also a reason why configuration files are plaintext and not tarred/zipped.)

good luck anyway.
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Post by tomfra »

timvw,

I am not worried about the space it takes at all. I am worried about the performance issue. In my opinion, it is more work for Apache to load a 60KB file than a 25KB file - and yes, the few characters on each line can make such a big difference.

Tomas
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

- How many times do you plan to (re)load the configuration then?
- Have you already measured the difference in loading time between a 60kb file and a 25kb file?
- Presume apache would allow you to pass multiple hosts separated by a comma. In that case apache would have to loop through a _big_ string and find every , that separates the hosts. I don't think performance will be very different.



Btw, i believe you have to separate them with a space " ".
From the manual:

Allow directive
Syntax: Allow from all|host|env=env-variable [host|env=env-variable] ...

Allow from 192.168.1.1 10.250.1.13
Post Reply