Hi there folks,
The default behaviour of WordPress is to redirect to “/” when there’s “/index.php” at the end of the URL. Since 3.7 WordPress is automatically recognizing Nginx and enables “pretty” permalinks. Plus Nginx Helper plugin should be able to remedy this.
However “nginx+wordpress (+fastcgi_cache) (+W3TC)” is producing 404 error when “index.php” is appended at the end of the URL. Valid redirection (stripping the “index.php”) only happens on the homepage.
This is the case with many websites out-there that use Nginx, rtcamp included. For example take a look at these pages with “index.php” at the end. For the sake of the experiment also try their homepages with “index.php” appended.
https://rtcamp.com/wordpress-nginx/tutorials/single-site/fastcgi-cache-with-purging/index.php
https://danielmiessler.com/blog/ultimate-speed-wordpress-nginx/index.php
http://www.makeuseof.com/tag/minix-z64-windows-edition-review/index.php
They all produce 404 error but they should redirect to a clean version of the same URL. What is surprising is that the last website uses W3TC and still has this problem.
However not all websites on Nginx are the same. Check these URLs for example. They behave as they should.
https://yoast.com/how-to-clean-site-structure/index.php
https://deliciousbrains.com/hosting-wordpress-yourself-nginx-php-mysql/index.php
Now I have the same problem and I was trying to solve it but I came up with one ugly solution that causes even more problems.
Putting:
if (!-e $request_filename) { rewrite .*$ /index.php last; }
before:
location ~ \.php$ { try_files $uri =404; ........ }
solves the problem but messes with my other custom redirection rules which I was shuffling around and still couldn’t make them right. Plus we all know that IfIsEvil.
I guess the key pieces of code in solving this problem are:
location / { try_files $uri $uri/ /index.php?$args; }
and:
try_files $uri =404;
As far as I understand, for some reason the first one is not identifying the “index.php” in the URL (except for the homepage - “/”), thus the second one is producing 404 error when “index.php” file is accessed directly.
Elegant solution for this problem would be appreciated.