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

Jorey Bump list at joreybump.com
Thu Feb 10 19:51:26 EST 2005


Graham Dumpleton wrote:
> 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?
> 
> 
> Make sure you turn off MultiViews. Add to your .htaccess file:
> 
> Options -MultiViews
> 
> Alternatively, don't set it in the first place in the main Apache
> configuration for that directory. Turning this off in a .htaccess
> file will require you to have appropriate rights to do so.
> 
> You should then be able to avoid using a .py extension if configuring
> use of publisher as:
> 
> SetHandler python-program
> 
> This cannot be done if you used:
> 
> AddHandler python-program .py
> 
> The MultiViews option can cause lots of problems when using
> mod_python and is frankly better always turned off.

I've been using this configuration for a long time with no problems:

         <Directory /var/www/myhost/site>
                 AddHandler python-program .py
                 PythonHandler mod_python.publisher
                 PythonDebug On
                 Options MultiViews
         </Directory>

This allows the type of URLs the OP desires. The only caveat that I'm
aware of is that you *must not* have similar names with different
extensions (foo.py, foo.php, foo.html, foo.jpg, etc.), or there will be
unexpected results when apache tries to guess which one to use.

versions: apache 1.3.x, mod_python 2.7.x



More information about the Mod_python mailing list