Apache Location directive for dynamic content fails if nested path

3.9k Views Asked by At

I'm using Apache 2.2x. Most of the content is generated via mod_perl. So, it's dynamic content that has no filesystem mapping. Perfect use of < Location >.

Apache config:

<Location /finance_module1>
  SetHandler perl-script
  PerlResponseHandler Finance::Module1
</Location>

<Location /finance/module2>
  SetHandler perl-script
  PerlResponseHandler Finance::Module2
</Location>

Module1 works, and is shown here to show that my setup otherwise works.

Module2 does not work. Apache says "File does not exist: /home/joe/www/htdocs/finance". The only difference between the module configurations is that Module2 location contains multiple slashes (what I'm calling a nested path).

About the "File does not exist" error: Of course it doesn't exist -- it's a Location, not a File or Directory. So why does this happen?

I would like to be able to use paths with multiple slashes because I've got a lot of mod_perl modules, and it would be nice to categorize for purposes of control. For one trivial instance, robots.txt could simply say:

Disallow: /finance/

The Apache docs specifically state that < Location > directives need not map to the filesystem, and are well-suited for dynamically generated content.

What am I doing wrong? Is there a workaround? (Besides the obvious "just don't do that").

Thanks.

2

There are 2 best solutions below

1
On BEST ANSWER

Answering my own question, for the benefit of anyone else wondering the same thing.

Short answer, use LocationMatch.

In the example above, say the urls are /finance/module1 and /finance/module2. Having the "finance/" path allows all the finance handlers to be configured as a group, in situations where that's desirable.

For example:

<LocationMatch /finance/.*>
  SetHandler perl-script
  PerlAccessHandler foo
</LocationMatch>

<Location /finance/module1>
  SetHandler perl-script
  PerlResponseHandler Finance::Module1
</Location>

<Location /finance/module2>
  SetHandler perl-script
  PerlResponseHandler Finance::Module2
</Location>
3
On

Slight typo perhaps?

<Location /finance_module1>

vs.

<Location /finance/module2>

Not sure if that is the issue.

Perhaps this (add to httpd.conf)

Alias /finance "path-to-files"
<Directory "path-to-files">
  Options +Indexes
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

Then try the script. You could also make an empty folder there perhaps?