Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a legacy web application on which I need to set access control based on the URL.

There are only two possibilities: allow from all or allow from my domain.

I believe I can do something like:

<Location /app/one-part>
   Allow from all

<Location /app/another-part>
   Allow from .foo.tld

<Location /app/yet-another-part>
   Allow from .foo.tld


The problem is that this particular application has hundreds of /app/thinguie URLs, and I don't want to code them all like I showed above.

Is there a way to do something like

<Location from file dom.txt>
   Allow from .foo.tld

<Location from file all.txt>
   Allow from All

and two files with the /app/whatevers listed?

thanks in advance.

Oh, by the way, there is no pattern and therefore no regular expression I can use to filter elegantly. :(

share|improve this question
Can you post the real data? I wonder that can we do with a DirectoryMatch directive. – quanta Sep 16 '11 at 2:52
@quanta. In reality it is the same application, and the path represents a database. Some databases need to be accessible from the internet, some do not. There is not much a Match can do. – Marcelo Morales Sep 16 '11 at 11:06
If so, check out the @SparX's suggestion. You can use echo -e "\t..." to keep formating and also notice that you should use <Directory> directive instead of <Location> for access control. – quanta Sep 16 '11 at 11:13
up vote 0 down vote accepted

The apache directive "Location" only accepts URL-path or URL as parameter and there is no way to read an external list. What I would suggest is, create a script to generate a custom conf which you can include in your apache conf.


[sparx@E1]$ cat file-foo.txt

Now create a simple bash script to generate the custom conf.

for x in `cat file-foo.txt`
echo "<Location $x>"
echo "Allow from .foo.tld"
echo "<\Location>"

Now execute the script and redirect the output to say, my-foo.conf

[sparx@E1]$ ./ > my-foo.conf
[sparx@E1]$ cat my-foo.conf
<Location /my/local>
Allow from .foo.tld
<Location /my/src>
Allow from .foo.tld
<Location /my/local/src>
Allow from .foo.tld

Now, the conf file is generated. Verify it and include in your main apache conf.

Include "path/to/my-foo.conf"
share|improve this answer
This was the way chosen. – Marcelo Morales Sep 19 '11 at 14:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.