[mod_python] Bizarre problems with rewriting URLs?

Graham Dumpleton grahamd at dscpl.com.au
Sun Oct 15 23:28:59 EDT 2006

Please keep the discussion on the mod_python mailing list. Ie., use
reply-all and not just reply.

Aaron Gallagher wrote ..
> On Oct 15, 2006, at 6:31 PM, Graham Dumpleton wrote:
> > By all means post that part of your configuration which is  
> > relevant, but also
> > state which version of mod_python you are using. Also make it clear 
> > whether you
> > have different parts of the URL namespace with their own PythonHandler
> > directives and whether you have separated them if possible by  
> > tagging them
> > against different Python interpreter instances using PythonInterpreter
> > directive or otherwise.
> Here's excerpts from my configuration files:
> <Directory /home/gethabbo/public_html>
>          SetHandler mod_python
>          PythonHandler questionable
>          PythonAuthenHandler questionable
>          PythonOption site_name gethabbo
> </Directory>
> <Directory /home/gethabbo/public_html/editor>
>          AuthType Basic
>          AuthName "Questionable"
>          Require valid-user
> </Directory>
> RewriteMap lowercase int:tolower
> RewriteMap vhost txt:/etc/apache2/vhost.map
> # Use the dynamic virtual host map.
> RewriteCond %{REQUEST_URI} !^/icons/
> RewriteCond %{REQUEST_URI} !^/cgi-bin/
> RewriteCond %{REQUEST_URI} !^/mail/
> RewriteCond %{REQUEST_URI} !^/phpmyadmin/
> RewriteCond %{REQUEST_URI} !^/mt/
> RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
> RewriteCond ${vhost:%1} ^(/.*)$
> RewriteRule ^/(.*)$ %1/public_html/$1 [L]
> And the relevant line in my map:
> www.gethabbo.com        /home/gethabbo
> > No. It is a known problem with mod_python that the order of  
> > directories in
> > sys.path can be random. As a result, if you use the same module  
> > name in
> > different handler directories, you can get strange things  
> > happening, more so if
> > you are using the worker MPM on UNIX.
> Okay. I need to find a way to determine where the Directory is that  
> the handler is defined for. Is there a way to access the  
> configuration other than PythonOptions from the req object?

On this later issue of determining what the handler root is, it depends
on which version of mod_python you are using.

In mod_python 2.X, you had to use:

        # In mod_python 2.X have the req.get_dirs() method.
        handler_root = req.get_dirs()["PythonHandler"]

In mod_python 3.0, 3.1 and 3.2 you would use:

        # In mod_python 3.X have the req.hlist member.
        handler_root = req.hlist.directory

Note though that in both cases, if the handler directive was inside of
a Files directive, the value was wrong due to problems with mod_python.
You would also get a bogus value if using the Location directive.

In mod_python 3.3, the preferred way (if using new importer) is:

        handler_root = apache.get_handler_root()

The req.hlist.directory method also still exists, but for cases like the
Files directive and other cases it will be None and one is supposed
to look back through req.hlist.parent to find context in which handler
was specified. If you use apache.get_handler_root() you don't have
to do that and it will always return correct value without having to
look through the mod_python internals to get it.

In respect of your rewrite problem, don't know. When I get a chance
will go back and read your original description of the problem to see
if I can work out what the real issue is.


More information about the Mod_python mailing list