我在虚拟主机部分有以下内容:
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/local.mysite/wordpress/$1
在我的testing中,我发现添加一个RewriteRule ^/wordpress/wp-content/(.*)$ /wp-content/$1 [L]的重写规则对于像下面这样的URL没有任何影响:
http://local.mysite/wordpress/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=....
这是因为名称中包含.php所有请求都传递给fcgi,因此所有重写规则都将被忽略?
如果使用proxypassmatch或proxypass,它将传递由php-fpm进程处理的php脚本,而php-fpm进程将忽略.htaccess规则。 一种避免这种情况的方法是使用apache sethandler,正如在这个答案https://serverfault.com/a/672969/189511中所解释的,
<FilesMatch \.php$> SetHandler "proxy:unix:/path/to/socket.sock|fcgi://unique-domain-name-string/" </FilesMatch>
我会在这里复制完整的解决scheme
经过几个小时的search和阅读Apache文档,我想出了一个允许使用池的解决scheme,并且允许.htaccess中的Rewrite指令即使在URL包含.php文件时也可以工作。
<VirtualHost ...> ... # This is to forward all PHP to php-fpm. <FilesMatch \.php$> SetHandler "proxy:unix:/path/to/socket.sock|fcgi://unique-domain-name-string/" </FilesMatch> # Set some proxy properties (the string "unique-domain-name-string" should match # the one set in the FilesMatch directive. <Proxy fcgi://unique-domain-name-string> ProxySet connectiontimeout=5 timeout=240 </Proxy> # If the php file doesn't exist, disable the proxy handler. # This will allow .htaccess rewrite rules to work and # the client will see the default 404 page of Apache RewriteCond %{REQUEST_FILENAME} \.php$ RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f RewriteRule (.*) - [H=text/html] </VirtualHost>根据Apache文档,SetHandler代理参数需要Apache HTTP Server 2.4.10。
我希望这个解决scheme也能帮助你。