I have nginx running wordpress. Weird thing is the site won't 404 and instead rewrites the URL to the homepage. Any URL with a .php in the string will 404 correctly but /foo will not 404. Any help would be appreciated.
example.com/foo.php will 404
example.com/foo will not 404 and instead just loads the homepage.
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
#try_files $uri $uri/ =404;
}
# pass the PHP scripts
#
location ~ \.php$ {
fastcgi_intercept_errors on;
include snippets/fastcgi-php.conf;
# With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
error_page 404 = /404.html;
location = /404.html {
root /home/web/error-pages;
internal;
}
I've been able to narrow this down to my nginx (Ubuntu 16.04, PHP 7, MySQL) because even a fresh install of WordPress has the same behavior.
$ sudo service nginx reload
try_files $uri $uri/ /index.php?$args;
sends anything that isn't a static file to WordPress. Which is actually a desired behaviour, as it allows WordPress to see every request and implement pretty permalinks (if you have them enabled). Are you not seeing a WordPress generated "not found" page?