Gladiator
Gladiator

Reputation: 176

PHP not working with rewrite rules that do not have "php" extension without "R" flag in Apache + PHP-fpm

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.

Upvotes: 0

Views: 257

Answers (1)

Alexey
Alexey

Reputation: 3484

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

Upvotes: 0

Related Questions