[mod_python] how do I eliminate the .py extension in url?

Jason Stitt jason at pengale.com
Thu Feb 10 19:14:05 EST 2005


URL cruft does seem to be a consequence of using publisher, just 
because of the way it maps URLs to modules and functions. Mod_rewrite 
is one solution, but annoying.

I've decided to just write my own handler. That way I can set one 
central handler for my entire domain and route requests from there by 
running regexps on the URL, or using any other method I desire. If you 
really want everything to be filesystem-based, this might need some 
modification.

Here's the relevant section of my conf file, minus actual dir names. 
It's worked so far. If anyone spots a potential problem I would of 
course appreciate being warned :)

<Location />
     SetHandler mod_python
     PythonPath "sys.path+['/server/dir/site-python']"
     # in /server/dir/site-python/index.py there is an index() function
     PythonHandler index::index
</Location>

DocumentRoot /server/dir/static

<LocationMatch "(.+?)\.(jpg|gif|png|css|html)">
     SetHandler default-handler
</LocationMatch>

A directive similar to the last one should also allow php or other 
scripts to coexist with python, which I'm looking into as I am porting 
a site incrementally from php to mod_python.

-Jason


On Feb 10, 2005, at 5:39 PM, Jef Dodson wrote:

> Also, it's not a very general solution.  I would like to be able to 
> access any number of scripts
> without having the .py show up in the URL.  I am sure it is possible 
> because I had it working
> under Linux, but I am now trying to get it working under BSD so I'm 
> wondering if maybe there is
> some option that I'm missing in my httpd config file that was there by 
> default on the Linux
> installation.  Anyone have any ideas on this?
>
> Jef
>
> --- Graham Dumpleton <grahamd at dscpl.com.au> wrote:
>
>> Chris Jackson wrote ..
>>> If you rename my_script.py to index.py, you can just reference your
>>> handler like this:
>>>
>>> /scripts/my_handler
>>
>> Except that calling things "index.py" opens up another big can of 
>> worms
>> if using publisher. See:
>>
>>   http://issues.apache.org/jira/browse/MODPYTHON-9
>>   http://issues.apache.org/jira/browse/MODPYTHON-10
>>   http://issues.apache.org/jira/browse/MODPYTHON-11
>>
>> Although some disagree, mod_python.publisher is broken in a number of
>> ways and needs a good overhaul.
>>
>> Soon maybe I will hack together something to give same style of 
>> interface
>> as publisher on top of Vampire just to show how much better things 
>> could
>> be. Alas, probably no time to do so. :-)
>>
>> Graham
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.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