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?

link|improve this question
feedback

2 Answers

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.

link|improve this answer
feedback

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.

link|improve this answer
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 3 '10 at 16:00
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.