PHP-FPM 不適用於 htaccess

PHP-FPM 不適用於 htaccess

我有一個VirtualHost

<VirtualHost *:80>
DocumentRoot "/var/www/html/example.com"
ServerName example.com
ServerAlias *.example.com
<Directory "/var/www/html/example.com">
    Require all granted
    Options -Indexes +FollowSymLinks -ExecCGI
    AllowOverride All
    DirectoryIndex index.php
    <IfModule mod_proxy_fcgi.c>
        RewriteEngine On
        RewriteBase /
        RewriteOptions InheritBefore        
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteRule ^([^\.]+\.php)$ fcgi://127.0.0.1:9000/var/www/html/example.com/$1 [L,P]
    </IfModule>
</Directory>
</VirtualHost>

和一個.htaccess位於/var/www/html/example.com/mysub/.htaccess.在文件內部.htaccess,我有:

Options -MultiViews
RewriteEngine On
RewriteBase /mysub

Options +FollowSymLinks

RewriteCond $1 !^(index\.php|assets|css|js|favicon\.ico|robots\.txt)

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

問題:example.com我可以在瀏覽器中正常導航。但是,如果我嘗試去example.com/mysub,它會顯示我example.com/index.php而不是example.com/mysub/index.php

我認為這意味著$1VirtualHost RewriteRule 中不包含mysub目錄前綴?這是為什麼?我認為這兩個檔案中的 RewriteBase (不同)可能是問題所在,但修改它並沒有改變輸出。

我相信問題出在 VirtualHost mod_rewrite 中。在不同的伺服器(Centos 5)上,網站運行完美(儘管我沒有使用 php-fpm)。我不想修改 htaccess,因為它是第 3 方程式碼的一部分。

PHP 5.4; CentOS 7;阿帕契2.4

編輯:當我將 htaccess 重寫移至 VirtualHost 檔案並修改路徑以使用 / 基底時,它就可以工作。但這並不理想,因為第三方程式碼可以隨時使用修改後的 htaccess 進行更新。

答案1

將重寫移到 VirtualHost 的 Directory 指令之外解決了這個問題。

<VirtualHost *:80>
DocumentRoot "/var/www/html/example.com"
ServerName example.com
ServerAlias *.example.com
<Directory "/var/www/html/example.com">
    Require all granted
    Options -Indexes -MultiViews +FollowSymLinks
    AllowOverride All
</Directory>
RewriteEngine On
RewriteOptions InheritBefore

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond $1 ^(.*\.php(/.*)?)$
RewriteRule ^(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000%{DOCUMENT_ROOT}/$1 [L,P]
</VirtualHost>

相關內容