Page 1 of 1

Allow/Deny directive & multiple IPs?

Posted: Fri Feb 04, 2005 2:50 pm
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

Posted: Fri Feb 04, 2005 3:31 pm
by timvw
What about the Include directive? Btw, don't forget this configuration file is only read when apache is starts/(re)loads...

Posted: Fri Feb 04, 2005 3:45 pm
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

Posted: Fri Feb 04, 2005 3:48 pm
by feyd
write a script to handle the file's formatting and whatnot?

Posted: Fri Feb 04, 2005 3:52 pm
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

Posted: Sun Feb 13, 2005 8:06 pm
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

Posted: Mon Feb 14, 2005 12:38 am
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.

Posted: Mon Feb 14, 2005 11:31 am
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

Posted: Mon Feb 14, 2005 12:00 pm
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