WordPress 404 Error
Recently UpdatedSymptoms:
– WordPress site shows error 404
– Using only Nginx in Plesk hosting settings
– Error log in PHP shows generic error 404 Not Found
Affects: WebHosting | Linux Plesk Reseller Hosting
When we see the error 404 in the browser, it means the webserver cannot find the requested page to display it.
Reset WordPress Permalinks
Some incorrect settings or plugins may have added incorrect rules to the .htaccess file or may not match the WordPress settings with the rewrite rules in the .htaccess file.
We can reset the URL structure of WordPress via the wp-admin
Choose WordPress > Log in > Settings > Permalinks > Save.
Restore .htaccess to default format
The .htaccess is a configuration file that contains commands for the Apache webserver.
One of its main functions is to rename зас URLs to a more friendly format.
The URL in the form https://example.com/?page_id=1662 is automatically renamed to https://example.com/mypage using the .htacess.
We can place the default .htaccess file of WordPress to fix possible 404 errors.
Rename the existing .htaccess to htaccess.txt
Create a new txt file named .htaccess
Append the following rules
# BEGIN WordPress
<fModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
<IfModule>
# END WordPressPlesk WordPress Nginx Only
In the Plesk control panel, the default function is to work simultaneously with the Apache and Nginx web servers.
If you select from the hosting settings of the domain, the service to be performed by Nginx, while in the settings of Apache & Nginx settings you have removed the proxy mode, a 404 error will appear when you try to view pages.
If we have installed the Plesk control panel on a dedicated server or VPS (not on a shared hosting account) we have an additional setting in the menu Apache & Nginx Settings.
There we need to place the WordPress rewrite rules, as Nginx cannot read the .htaccess file.
if (!-e $request_filename) {
set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location|status_phpfpm)) {
set $test "${test}C";
}
if ($test = PC) {
rewrite ^/(.*)$ /index.php?$1;
}If WordPress is in a folder, for example, mydomain.gr/wordpress
if (!-e $request_filename) {
set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location|status_phpfpm)) {
set $test "${test}C";
}
if ($test = PC) {
rewrite ^/(.*)$ /sub-dir/index.php?$1;
}