douaipi3965 2018-11-18 15:43
浏览 51
已采纳

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.

  • 写回答

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

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

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏