WordPress Theme’s 404.php not found, server defaults to Apache’s own 404 page

if I just type something to provoke a 404 Error on my WordPress installation, WordPress doesn’t load its own 404.php file, but the Apache server’s own 404 error message gets displayed.

What is wrong with my WordPress installation? Do I need to edit the Apache server’s config file and redirect to the WordPress 404.php page?

UPDATE:

Read More

I have partially managed to get this working, I missed the FileInfo directive in the /etc/apache2/sites-available/default file. Not all stuff get caught gracefully, though.

Related posts

Leave a Reply

2 comments

  1. Things are working the way they are supposed to, and possibly the only way they can work. Let me explain.

    Without an Apache module called mod_rewrite (or the equivalent Nginx or IIS component) requests to PHP pages have to go to an actual filesystem file. That is what you see with requests like 192.168.1.8/wordpress/?p=123. The file being accessed is the directory “index” fileindex.php. That request is the equivalent of 192.168.1.8/wordpress/index.php?p=123. What you are doing is requesting some other file/directory with requests like this one– 192.168.1.8/wordpress/asdasdasd— and no such file or directory exists in the filesystem.

    With mod_rewrite and .htaccess properly configured all requests get sent to index.php. Take a look at the stock WordPress .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
    

    That RewriteRule pushes everything (almost everything) to index.php. That allows WordPress to process any request, even requests for files that don’t physically exist on the system.

    Without pretty permalinks enabled– that is, with the “default” permalinks selected– WordPress will not even try to parse the requests so that is equivalent to not having mod_rewrite or .htaccess at all.

    And, if WordPress can’t parse the request, WordPress can’t load the theme’s 404.php. Apache, of course, still knows the request is bad and loads its own 404 message.

    So, without mod_rewrite, a proper .htaccess file, and pretty permalinks you get the behavior you describe, which is exactly how things are supposed to work.

  2. WordPress will only handle 404’s if pretty permalinks are enabled – go to Settings > Permalinks and choose one of the options other than default (or use your own).