php icon indicating copy to clipboard operation
php copied to clipboard

Incompatibility with FallbackResource and SetHandler

Open andrewnicols opened this issue 9 months ago • 4 comments

I've just encountered an issue whereby our FallbackResource is applied correctly, except where the URL requested ends in .php.

For example:

  • http://localhost/example.html => Uses FallbackResource
  • http://localhost/example.php => Does not use FallbackResource and results in a 404

It seems that it's because the docker-php.conf configuration file sets the PHP Handler for any file which matches .php, and therefore the FallbackResource (handler) is not applied.

<FilesMatch \.php$>
	SetHandler application/x-httpd-php
</FilesMatch>

https://github.com/docker-library/php/blob/master/8.4/bookworm/apache/Dockerfile#L97-L99

This has been raised (and rejected) in the Apache Bugzilla: https://bz.apache.org/bugzilla/show_bug.cgi?id=52403#c7

There seems to be a few possible solutions:

  1. Use AddType instead of AddHandler or SetHandler. I'm not sure if this is suggestion on the bz issue is from the Apache team, or is an observeration. I'm not sure whether this is a viable option
  2. Wrap the SetHandler call in a conditional
  3. Switch to mod_rewrite (not generally recommended now that FallbackResource exists)

Re 2, the change would be something like this:

<FilesMatch \.php$>
    <If "-f %{REQUEST_FILENAME}">
        SetHandler application/x-httpd-php
    </If>
</FilesMatch>

(Suggestion found here: https://stackoverflow.com/questions/50439963/apache-fallbackresource-configuration) This would likely have a performance impact, but I would imagine no worse than using mod_rewrite.

I've tested the conditional SetHandler locally and it works as expected.

andrewnicols avatar Apr 02 '25 01:04 andrewnicols