Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer

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.

share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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