Score:1

RewriteRule won't match if trailing slash present, throws nginx 404

cn flag

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.)

kz flag
If you are getting a 404 response from an Nginx server then this evidently has nothing to do with your `.htaccess` file (which obviously only applies to Apache). Are you sure you're using Apache at all?!
cn flag
@MrWhite looks like you're right... two "websites" in the same account run on apache and nginx, apparently. I just assumed it was a nginx (reverse?) proxy in front of apache because mod_rewrite *half* works...
kz flag
Yes, I too would have assumed an Nginx proxy in front of Apache if it wasn't for your last example... "`/foobar` — fails, as expected, but with a pretty 404 ErrorDoc from nginx". But then again, if mod_rewrite "half works" then maybe this is just a proxy. I assume then that `foo.php` is served from Apache? If you remove `.htaccess` altogether and request `/foo`, is `/foo.php` still served? (This is could indicate that MultiViews is enabled in the server config, so `.htaccess` may not be doing what you think it's doing?)
cn flag
@MrWhite without `.htaccess` `/foo.php` is not served. Thank you for your input, I've contacted support now, because this looks more and more like misconfiguration on their part.
Score:1
cn flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.