2

I have a Django app that handles "/admin/" and "/myapp/". All the other requests should be handled by Apache.

I've tried using LocationMatch but then I'd have to write a negative regex. I've tried WSGIScriptAlias with the /admin/ prefix but then the wsgi_handler receives the request with the /admin/ part cut off.

Is there a cleaner way to make mod_wsgi only handle certain requests?

Frederik
  • 133
  • 6

2 Answers2

5

Use:

WSGIScriptAliasMatch ^/(admin|myapp) /some/path/django.wsgi/$1

This should preserve SCRIPT_NAME as matching root of web site so that urls.py still works for entries starting with admin and myapp.

Graham Dumpleton
  • 6,090
  • 2
  • 21
  • 19
0

Just using an alias in my apache configuration has always worked for me:

  Alias /media /sites/mysite.org/www/media
  <Location /media>
    Order allow,deny
    Allow from all
  </Location>

It gets processed before mod_wsgi get near it.

From the django book http://www.djangobook.com/en/beta/chapter21/:

If you deploy Django at a subdirectory — that is, somewhere deeper that “/” — Django won’t trim the URL prefix off of your URLpatterns. So, if your Apache config looks like:

<Location "/mysite/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonDebug On
</Location>

The all your URL patterns will need to start with "/mysite/". For this reason we usually recommend deploying Django at the root of your domain or virtual host.

gm3dmo
  • 10,057
  • 1
  • 42
  • 36
  • For media this works because it is a subpath. But what if I want to let the root "/" be handled by apache, and only certain URLs (/admin/, /myapp/) by mod_wsgi? – Frederik Jun 03 '10 at 16:00