sankarNarayanan / modwsgi

Automatically exported from code.google.com/p/modwsgi
0 stars 0 forks source link

Fallback resource for directory when using AddHandler. #184

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The DirectoryIndex directive allows one to define a resource which is invoked 
when accessing 
against a directory. This resource cannot however accept any additional path 
information.

The way around this is to use a rewrite rule such as:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /site.wsgi/$1 [QSA,PT,L]

Although this works, the resulting SCRIPT_NAME reflects the resource and not 
the directory. To 
get around that, one uses a fiddle such as:

def _application(environ, start_response):
    # The original application.
    ...

import posixpath

def application(environ, start_response):
    # Wrapper to set SCRIPT_NAME to actual mount point.
    environ['SCRIPT_NAME'] = posixpath.dirname(environ['SCRIPT_NAME'])
    if environ['SCRIPT_NAME'] == '/':
        environ['SCRIPT_NAME'] = ''
    return _application(environ, start_response)

In Apache 2.3 they have a FallbackResource which can be used in place of the 
rewrite rule to do 
same thing, but it still doesn't do the SCRIPT_NAME fixup. It may be desirable 
to implement a 
mod_wsgi specific mechanism the same as FallbackResource but which also does 
the 
SCRIPT_NAME fixup automatically.

Original issue reported on code.google.com by Graham.Dumpleton@gmail.com on 4 Mar 2010 at 11:18