[Gllug] Apache URL matching directives, fall through

Richard Lewis richardlewis at fastmail.co.uk
Wed Aug 11 14:57:02 UTC 2010


At Wed, 11 Aug 2010 15:06:04 +0100,
Richard Lewis wrote:
> 
> Hello GLLUG,
> 
> I'm trying to configure an Apache set up which matches a few URL
> patterns and serves static content "from" (or whichever preposition
> you think best) them, and then falls back on a mod_python handler for
> all other URLs.
> 
> I tried:
> 
> <VirtualHost *>
>     ServerName localhost
>     DocumentRoot /home/richard/app/web
> 
>     Alias /static /home/richard/app/web/static
>     <Directory /home/richard/app/web/static/>
>     	Order allow,deny
>      	Allow from all
>     </Directory>
> 
>     # ... similar directives for /styles, etc.
> 
>     <Location />
>     	Order allow,deny
>     	Allow from all
>     	SetHandler mod_python
>     	PythonPath 'sys.path+["/home/richard/app/python/"]'
>     	PythonHandler handle_request
>     </Location>
> </VirtualHost>
> 
> However, this fails (I think) because <Location> takes precedence over
> <Directory>.
> 
> So I tried replacing the <Directory>s with <Location>s (and removing
> the Aliases):
> 
>     <Location /static/*>
> 	Order allow,deny
> 	Allow from all
>     </Location>
> 
> However, the <Location /> still ends up serving every request.
> 
> I considered trying a regex for the fall through, mod_python case
> (instead of handling just "/"), but all I've come up with so far is a
> negative look-behind assertion:
> 
> <Location ~ "^/(?<!(static|styles).*$">
> 
> which fails because look-behinds must be of fixed width. And anyway, I
> don't really want a solution which depends on duplicating knowledge of
> the exception cases (i.e. specifying how to handle a subset of
> requests, and then re-stating that subset in the default case).
> 
> Maybe I'm thinking of Apache directives too much like a collection of
> cases in a switch structure?
> 
> Any ideas how to get this to work?
> 
Typically, I found an answer to this shortly after posting this
message. A bit of lateral thinking led me to discover the

SetHandler None

directive.

So I now have

    <Location />
        # ...
    	SetHandler mod_python
        # ...
    </Location>

    <Location /static>
	Order allow,deny
	Allow from all
	Options -Indexes
	SetHandler None
    </Location>

and it works as required.
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard Lewis
ISMS, Computing
Goldsmiths, University of London
Tel: +44 (0)20 7078 5134
Skype: richardjlewis
JID: ironchicken at jabber.earth.li
http://www.richardlewis.me.uk/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+----------------------------------------------+
| Support open access to scholarship           |
| http://freeculture.org/ http://www.doaj.org/ |
+----------------------------------------------+
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list