dongren1977 2013-11-06 19:29
浏览 60
已采纳

使用mod_rewrite时,WSGI错误地处理别名目录中的PHP脚本

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.

  • 写回答

1条回答 默认 最新

  • doujia1163 2013-11-07 00:54
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含