[mod_python] SetHandler trick to have pretty url's

Dan Eloff dan.eloff at gmail.com
Sun Jan 22 19:32:58 EST 2006


Actually I found this doesn't work well for me. I use a similar setup
with a config file that maps uris to python modules (initially I used
an automatic system like the publisher does, but I find this isn't
flexible enough), but FilesMatch works at the filesystem level. I want
to let apache handle all urls with a file extension, and mod_python to
handle any without a file extension.

So after playing around with it a bit, I settled on:

# don't invoke our python handler if the file has an extension, it
doesn't handle any addresses like that
<LocationMatch "^[^.]*$">
	SetHandler mod_python
	PythonHandler PyServer
	PythonDebug On
</LocationMatch>

I thought I might need a complex regular expression like yours, but my
tests show the above will still match a url with a . in the query
string, while denying any with a . before the ?

It's interesting to find someone else with a similar setup.

-Dan

On 1/9/06, courtney ludwin <courtneyludwin at yahoo.com> wrote:
> I was looking for a way to pretty up my mod_python
> url's the other day and I figured out a trick that
> works w/ the 'FilesMatch' directive in httpd.conf, I
> figure I'd share with the list....
>
>  <FilesMatch "(^[^\.]*$|^[^\?]*[\?]+[^$]+$)">
>     SetHandler python-program
>     PythonHandler common.dispatch.dispatcher
>     PythonDebug On
>   </FilesMatch>
>
> This match expression says anything without a file
> extension should be handled by dispatcher.py otherwise
> apache should handle it normally.  I wrote the
> dispatcher use a config file to map url's to
> mod_python handlers.
>
> Followed up a quick example in my blog:
> http://2centspoorer.blogspot.com/2006/01/creating-your-own-modpython-request.html
>
> Hope you find it useful.
>
> Thanks,
> Courtney
>
>
>
> __________________________________________
> Yahoo! DSL – Something to write home about.
> Just $16.99/mo. or less.
> dsl.yahoo.com
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>



More information about the Mod_python mailing list