Question

all. So I'm running Apache 2.2. I have a single VirtualHost that's used for a Django application (by way of mod_wsgi) as well as a PHP one that lives in a subdirectory. Normally, this is no problem. You can just Alias /subdir /path/to/phpapp followed by WSGIScriptAlias / /path/to/django.wsgi.

But, the complication is that this PHP application uses mod_rewrite to implement "Fancy URLs," which just means that '/subdir/foo/bar' will get rewritten to something like '/subdir/index.php?path=foo/bar'.

Here's my configuration:

<VirtualHost *:80>
    ServerName [snip]

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    Alias /phpapp/ /home/ubuntu/phpapp/
    <Directory /home/ubuntu/phpapp>
        Order allow,deny
        Allow from all
        RewriteEngine on
        RewriteCond $1 !^(index\.php|img|bin)
        RewriteRule ^(.*)$ index.php?__dingo_page=$1 [PT]
    </Directory>

    WSGIDaemonProcess foo user=ubuntu
    WSGIProcessGroup foo

    WSGIScriptAlias / /home/ubuntu/djangoapp/apache/django.wsgi
    <Directory /home/ubuntu/djangoapp/apache>
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

The problem is that whenever a rewrite takes place (e.g., I try to go to /phpapp or /phpapp/foo) the request gets handled by WSGI and I see my Django site's 404 page. If the address passes through (e.g., I go to /phpapp/index.php) then it is handled by PHP and works normally. I thought maybe that adding the [PT] flag to my RewriteRule would fix this problem, but it doesn't seem to have any effect on which handler is chosen. I've also tried SetHandler application/x-httpd-php in the Directory section for the PHP app.

I need the Django application to continue to handle any URLs that aren't specifically aliased to something else. There must be a way to make this work! Thanks.

Était-ce utile?

La solution

Using /phpapp wouldn't ever work because you have a trailing slash on that path for the Alias directive. Use:

Alias /phpapp /home/ubuntu/phpapp

By rights that Alias directive should then take precedence over WSGIScriptAlias for the sub URL.

I would suggest you enable logging by mod_rewrite and verify what the URL is being written to. So long as the rewritten URL still sits below /phpapp, it should be fine.

The alternative is to not use WSGIScriptAlias, but use the scheme as outline towards the end of:

That allows you to set things up so that the Python web application will only be used as a fallback if no static resource, including PHP, could be mapped.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top