We use apache, mod_php, and mod_wsgi to serve a central wordpress site, with some paths instead powered by Django, so for example these pages might be powered by Wordpress:
oursite.com/
oursite.com/video/
but these URL's might be Django-powered:
oursite.com/our-cool-django-app/
oursite.com/schedule/
Right now, we use a long list of WSGIScriptAlias to map particular paths to Django. This annoying and labor intensive.
So, is there a way that we can configure things such that:
- One or the other first attempts to handle the URL (I'm not too concerned) first
- If that handler returns a 404, try the other one
I'm particularly interested in an Apache solution, but will consider alternatives.
This is in response to your entertainment of alternatives.
I've hosted Django and WordPress on the same domain behind Nginx using
php5-fpm
for WordPress and relying on Nginx'sX-Accel-Redirect
to return undefined URLs to the WordPress upstream.The Nginx configuration starts with known patterns which WordPress should handle: an index page, a few top-level content pages or top-level sections, and/or the pattern for blog posts. This means most WordPress URLs can be caught with a dozen or fewer URL patterns.
Everything else is routed to the Django upstream.
What about new pages or changes to the WordPress site? Rather than update the URL patterns for every WordPress page or section added, the Django app uses a custom 404 handler to redirect the request to the WordPress upstream.
By redirecting the requests the redirect middleware won't "see" any 404 errors, so if you want to use the redirect feature it should be added here. The
/wordpress/
location is defined as an internal location in the Nginx configuration.I've written a little bit more about using X-Accel-Redirects for this purpose, though I recognize this doesn't answer the specific question.
Hopefully it gives you some ideas of you could employ
X-Sendfile
to do something similar withmod_php
andmod_wsgi
.Read:
Use the AddHandler/mod_rewrite method.
If a URL can't be handled by your PHP application because there is no corresponding .php file, it will fall through to your WSGI application.