FIX: Website only shows the homepage 404 WordPress

The headache

I gave myself a headache this week by accidentally throwing away my entire WordPress blog in FTP.

Fortunately I have set up a backup in cPanel with Installatron. Only, after the backup restore my website still didn’t work properly. I could only go to the homepage and I also received an error message this time:

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

404 usually means your website doesn’t exist..


So, you’re telling us that you’re not a web developer?

Well, sort of. I work as a system engineer and in my spare time I hobby with my blog and some web design.

So no, I did not come up with the solution myself, I just know how to Google. I had difficulty finding out why this is the solution and what it does exactly. I rather know what code does before I implement it.

Below I give you the solution with explanation.


We’ll let’s fix “Only the homepage works, rest 404“.

Okay, well the problem is your .htaccess file. This probably has a corrupt setting, or at least no longer matches what it should be (for example by a backup restore).

First, try to re-name your .htaccess file into something like .htaccess_old and see if you website comes back up. If this is the case, but only a few pages work, please continue.

Open your .htaccess file and then add the following at the top:

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

Let me explain this to you..

Everything is fully written out on the Apache website. Unfortunately it is so much information that it took me a while to figure it out. Due to this I’d love to explain it to you as ‘Explain Like I’m 5’.

Is something still not clear? Please leave a comment.


RewriteEngine On

FIX: Website only shows the homepage 404 WordPress
FIX: Website only shows the homepage 404 WordPress

Rewrite Engine is a programming module in Apache. It will allow you to rewrite URL requests. With RewriteEngine On you will enable the module.

From Apache.org: To enable the rewrite engine in this context, you need to set “RewriteEngine On”


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond’ checks whether a condition matches before the next RewriteRule can be applied.

% {REQUEST_FILE}’ is a variable set by the server that contains the request URL. the -FILE part is misleading though. It can be all type of items. Including Directories.

‘-f’ Stands for -file and means that a file has to exist under the request URL before we can continue, but the ‘!’ means the opposite, so there should be no filename under that request URL.

Because permalinks are never a filename, the above RewriteCond will almost always be True.

In a nutshell:

  • RewriteCond: Checks whether the condition matches.
  • % {REQUEST_FILE}: Is a variable that’s converted to a request URL by the apache server.
  • -f: means that a File must exist under the request URL.
  • !: An exclamation point means that the “-f” sign is used the opposite way.

RewriteCond %{REQUEST_FILENAME} !-d

This looks like the previous RewriteCond, only the -d is different from the -f.

‘-d’ Stands for -directory and means that a directory has to exist under the request URL before we can continue, but the ‘!’ means the opposite, so there should be no directory under that request URL.

In a nutshell:

  • RewriteCond: Checks whether the condition matches.
  • % {REQUEST_FILE}: Is a variable that’s converted to a request URL by the Apache server.
  • -d: means that a Directory must exist under the request URL.
  • !: An exclamation point means that the “-d” sign is used the opposite way.

RewriteRule ^(.*)$ index.php/$1 [L]

RewriteRule: is only triggered if the above RewriteConds are true.

Since you never place a file or directory under a permalink name on your server, these two are almost always true and trigger your RewriteRule. The RewriteRule then directs you to the correct URL.

  • ^: Matches the beginning of the string;
    ^(WordPress) matches a string that begins with WordPress.
  • (  ): Groups several characters into a single string;
    (WordPress)$ Means the end of a string ending with WordPress.
  • .: Matches any single character;
    b.s will match bas, bos, bus, and so on.
  • *: Repeats the previous match zero or more times;
    D* matches D, DD, DDD, DDDD~, but will also match an empty string.
  • $: This matches the end of the string;
    (Blog)$ matches a string that ends with Blog.
  • $1: The variable $1 will be replaced with whatever text was matched by the expression inside the parenthesis in the Pattern;
    A request for http://example.com/product/r14df/view will be mapped to the path/var/web/productdb/r14df (directly from Apache).
  • [L]: causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed (directly from Apache).

If you want to know more about all this, I want to refer you to the Apache website.

Links I’ve used:


The complete error message

Not Found

The requested URL /site/website was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work as a PowerShell DevOps Engineer. In my spare time I write about interesting stuff that I encounter during my work.

One thought on “FIX: Website only shows the homepage 404 WordPress”

  1. Thank you so much For your Information. It Will be Helpful for newbies. Hope You will Give Us more Blog Like This in the Future.

Leave a Reply

Your email address will not be published. Required fields are marked *