2018-11-18 15:43
浏览 43

PHP没有使用在Apache + PHP-fpm中没有“R”标志但没有“php”扩展名的重写规则

We are currently trying to switch our web server to apache 2.4 running with PHP via php-fpm and mod_proxy_fcgi in Docker environment.

We used to have URL rewrite rule as follows in Apache config and it worked well with previous "mod_php" setup:

RewriteRule ^/test$ /test.php [QSA]

However, once we switch to Apache 2.4 + PHP-FPM with following setup in Apache config, the php stops working for this URL (/test):

RewriteEngine On
RewriteRule ^/test$ /test.php [QSA]

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/html/$1

With this setting, the URL http:///test leads to a plain text on the screen showing the content of "test.php", which means the page was not being fed into PHP at all; however, if I change the rewrite rule flag from "QSA" to "R", PHP starts to work and everything is fine.

It seems "ProxyPassMatch" line is executed before RewriteRule when "R" is not there. So if that is the case, does anybody have solution to this problem? I'm sure there are a lot of web sites using clean URLs, which usually don't have "php" extension, for PHP pages...

Thanks in advance.

图片转代码服务由CSDN问答提供 功能建议

我们正在尝试将我们的Web服务器切换到运行PHP的apache 2.4,通过php-fpm和mod_proxy_fcgi在Docker环境中运行 。


RewriteRule ^ / test $ /test.php [QSA ]

然而,一旦我们切换到Apache 2.4 + PHP-FPM并在Apache配置中进行以下设置,php就会停止工作 此URL(/ test):

  RewriteEngine On 
RewriteRule ^ / test $ /test.php [QSA] 
ProxyPassMatch ^ /(。* \。php(/  。*)?)$ fcgi:// php:9000 / var / www / html / $ 1 

使用此设置,URL http:/// test 在屏幕上显示一个纯文本,显示“test.php”的内容,这意味着该页面根本没有被输入PHP; 但是,如果我将重写规则标志从“QSA”更改为“R”,则PHP开始工作,一切正常。

似乎“ProxyPassMatch”行在RewriteRule之前执行时“ R“不存在。 那么如果是这样的话,有没有人能解决这个问题呢? 我确信有很多网站使用干净的URL,对于PHP页面通常没有“php”扩展名...


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongqiu8375 2018-11-18 21:24

    I think it has to do with the fact that QSA does not do 30x HTTP redirect as R does, so there is no second request (as in case with R modifier) and therefore no request with .php at the end and therefore this is not fed to PHP interpreter. As a quick solution I would consider modification of the ProxyPassMatch regexp to add the test and any other non-php ending URLs to be supplied to PHP

    打赏 评论

相关推荐 更多相似问题