RewriteRule – Fix Nginx 404 Error with Trailing Slash

.htaccessmod-rewrite

With this .htaccess

RewriteEngine on
RewriteRule ^foo$ foo.php
RewriteRule ^foo/$ foo.php

…I get the following behavior, when I request

  • /foo — works, I get foo.php
  • /foo/ — fails unexpectedly with a bare 404 from nginx
  • /foobar — fails, as expected, but with a pretty 404 ErrorDoc from nginx

Note: there is no folder foo present.

Am I missing something or is this the hosting provider's fault, like a nginx proxy misconfiguration? On a different apache, this setup works as expected.
(I'm trying to drill down why WordPress's (default-ish) .htaccess doesn't work.)

Best Answer

E-mailed support, they fixed it.
From what phpinfo tells me, $_SERVER['SERVER_SOFTWARE'] changed from nginx to Apache...
For future searches: this was on the web host provider checkdomain.de.