HTTP Response 404 not found on all WordPress posts

This is a problem which lately has been plaguing me. If you have your own WordPress.org website hosted by a server which you pay for, you may encounter or have encountered this problem before. Google webmaster tools along with google adwords notified me that all of my post randomly started triggering HTTP 404 status codes; however, I was still able to visit each page and view its content perfectly. Anyway, with a lot of umming and ahhing, I have worked out a few different things.

  1. Often server technical support services use the same tools you have access to in order to diagnose your own site; they have no magical solution and no serious diagnostic programming skills (until proven otherwise- yes I had a bad experience with my technical support)
  2. The importance of getting familiar with your .htaccess file and it’s entries

What is the .htaccess file?

The .htaccess file is usually situated in the root (primary) directory of your webserver, often the same location of your index.html. It is a simple txt file which can be created in a basic txt editor like Notepad or Gedit (for ubuntu) and controls allot of configurable options which give navigational functionality to your site. You can perform security related tasks like blocking IP addresses or assigning permissions to directories. You can point to custom error pages and even control how people view your URLs etc.

As it turns out, someone, something, somehow had modified or replaced my .htaccess fileĀ  and it had no contents other than:

ErrorDocument 404 /index.php?error=404
#RewriteRule ^sitemap.xml sitemap-%{SERVER_NAME}.xml [L]
#RewriteRule ^sitemap.xml.gz sitemap-%{SERVER_NAME}.xml.gz [L]
# BEGIN WordPress

# END WordPress

The easiest way to modify or check whether this has happened to you is to FTP or go to your server’s admin page (i.e. cPanel) and check out your FileManager,
Download your .htaccess file (you may need to change the file managers settings to display hidden files) and open it with a txt editor. If yours looks like the above, it seems as though your permalink settings didn’t perform the rewrites correctly or something else strange happened. Anyway, it is supposed to look like:

ErrorDocument 404 /index.php?error=404
#RewriteRule ^sitemap.xml sitemap-%{SERVER_NAME}.xml [L]
#RewriteRule ^sitemap.xml.gz sitemap-%{SERVER_NAME}.xml.gz [L]
# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Make your edits, save your changes and re-upload into root directory. Ensure you keep a backup copy of your old and your new one on your local computer. Hope this helps.