How to fix the 404 Not Found Error in WordPress

How to fix the 404 Not Found Error in WordPress

In this write-up, we will show how to fix the ‘404 Not Found Error’ in WordPress.

The ‘Error 404 – Not Found’,

Many users make a mistake when changing their WordPress address and site address in their WordPress settings, and the next time they log in to their admin area, they see the error ‘Error 404 – Not Found’.

To fix this ‘Error 404 – Not Found’, we will discuss two different methods to change URLs

Method 1. Change URLs Using functions.php File.

You can follow this method when you cannot access your WordPress admin panel due to the ‘Error 404 – Not Found’.

To start, you have to connect to your WordPress website using an FTP client. 

Then, visit your WordPress theme folder. This is something like /wp-content/themes/your-theme-folder/.

Now, open your functions.php file and edit it using your text editors, such as Notepad or TextEdit.

Then, add the code given below to the bottom of the file.

 update_option( 'siteurl', 'https://example.com' );

update_option( 'home', 'https://example.com' );

Note: replace ‘https://example.com’ with your own site URLs.

Then, save the changes and upload the file back to your server using FTP.

Now, visit your site to see everything back to normal.

After your site is working properly, you can remove this code from your WordPress functions.php file.

Method 2. Change URLs Using wp-config.php File

 While changing URLs Using functions.php File, if you’re unsure which theme you have to edit or can not find your functions.php file, you can go with this method.

In this method, You have to add your website URLs to your WordPress configuration file named wp-config.php. This file contains important WordPress settings and is located in the root folder of your website.

You have to connect to your website using an FTP client to change this file. 

After that, locate the wp-config.php file in the root folder for your domain.

Then, add the code just above the line ‘That’s all, stop editing! Happy publishing’.

 define( 'WP_HOME', 'https://example.com' );

define( 'WP_SITEURL', 'https://example.com' );

Note: Replace ‘https://example.com’ with your own domain name.

After that, save your changes and upload them back to your server. 

Now, You can visit your site to ensure that everything is working properly.

The Posts Returning 404 Error

Some users may notice the 404 posts returning Error. This happens when they can access their site, their blog’s main page, but see the 404 Not Found Error when they visit one of their posts. You can fix this issue by the following method. 

Fixing The Posts Returning 404 Error

Let’s move on to fix WordPress posts returning 404 errors.

This generally happens if your .htaccess file got deleted or something goes wrong with the rewrite rules. 

Then, you have to fix your permalinks settings.

Visit Settings » Permalinks, and click on the Save Changes tab.

This updates your permalinks settings and flushes out the rewrite rules. In many cases, this solution fixes the WordPress posts 404 error. But, if this does not work for you and you are still facing the same issue, then you have to update your .htaccess file manually.

To do that, log in to your server using the FTP client, and modify the .htaccess file. This file is located in the same location where folders like /wp-content/ and /wp-includes/ are present. 

One thing you can do is to temporarily make the file writeable by changing the permissions to 666 and then following the above/original solution. After that, make sure to change the permissions back to 660. Another way is you can manually add this code in your .htaccess file:

 # BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>

# END WordPress

This way you can access your post easily.

To conclude- In WordPress, we may find difficulty logging in to the admin area or visiting any of our posts due to the 404 Not Found Error. In this write-up, we have tried to explain how you can resolve this, and we hope this tutorial help fix the 404 Not Found Error in WordPress. 

 If you are experiencing any other error on your site, you can fix it by following the steps told in our other article on what to do when you are logged out of the WordPress admin area.

Leave a Comment