How to fix the 404 Not Found error after changing WordPress Permalinks Structure?

Some WordPress users may encounter the 404 Not Found Error after they migrate the site to a new server. The error usually happens when you change the WordPress permalink structure.

The reason for the 404 Not Found error is that the original server hosting is powered by Apache while the new server is powered by Nginx. And the rewrite rule of Apache is different from Nginx.

To solve the problem, one of the effective solutions is that you can contact the server administrator to configure the Apache environment for you.

However, Nginx is fast and capable to handle more traffic than Apache. If you want to scale your business in the future, Nginx is certainly better than Apache. Therefore, you need to solve the problem once and for all.

In this article, we will introduce how to fix the 404 Not Found Nginx Error.

To fix the Nginx 404 Not Found Error in WordPress, you need to edit the Nginx configuration file and add a rewrite rule to the configure file.

How To Edit The Nginx Configuration File?

To edit the Nginx configuration file, you need to locate the path of the Nginx configuration file. If you are a beginner to WordPress with zero server knowledge, it’s difficult for you to find out the path of the Nginx configuration file. You can contact the server administrator for help or you can follow the steps below.

Step 1, Locate the Nginx configuration file.

The main Nginx configuration file is often named nginx.conf, and it includes various directives and settings for Nginx. In different operation systems, the location of the Nginx configuration file is different. The path of the nginx.conf in different operation systems is below, you can access it by FTP or file manager service provided by your hosting panel.

  • Ubuntu/Debian: /etc/nginx/nginx.conf
  • CentOS/Red Hat: /etc/nginx/nginx.conf

However, it is generally recommended not to modify the main nginx.conf directly. Instead, you should place your custom server configurations in separate files within the appropriate directories. In this case, we will add a snippet to the nginx.conf file to fix the Nginx 404 Not Found Error when changing the WordPress permalink structure.

Step 2, Add a snippet to the nginx.conf file by editing it.

The snippet can be added at the end of the server block. Below is the code you need to add to the nginx.conf file

if (-f $request_filename/index.html){  
               rewrite (.*) $1/index.html break;  
        }  
        if (-f $request_filename/index.php){  
               rewrite (.*) $1/index.php;  
         }  
        if (!-f $request_filename){  
               rewrite (.*) /index.php;  
         }

Below is the example to show the position you should add the snippet to the nginx.conf file. Make sure the snippet is inside the server block.

After you add the snippet to the nginx.conf file, save it and restart the Nginx if you can. Sometimes you don’t have to restart the nginx and it works.

Wrapping up

To fix the Nginx 404 Not Found error after changing the WordPress permalink structure, the key point is that you can locate the nginx.conf file and edit it. Contact your server administrator if you can’t locate the configuration file. Also, you can ask them to install the Apache environment for you.

However, compare with Apache, Nginx is Lightweight, efficient, event-driven, fast, scalable, reverse proxy, low memory, easy configuration, graceful reloads, modern protocols, and robust security.

We recommend you keep Nginx and fix the 404 Not Found Error by following the method we introduce above.

Scroll to Top