2

I want to create a custom 404 page, but I cannot seem to override the 404 which is in Wordpress itself. The reason I want a custom 404 page is that if I get 404 within my subdirectories I get directed to my wordpress-site's 404. I'd rather have a 404 for my whole domain.

I've only found solutions to do this within Wordpress-pages etc, but do I really have to? I guess my problem is the .htaccess-file, however if I mess this one up, my links will be broken on my Wordpress-site.

My .htaccess looks like this (although the first line is the one I want to add, but wordpress doesn't seem to care).

ErrorDocument 404 /404page.php

# 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

In short: My Wordpress-site is on the root of my domain and its 404 page is shown on all subdomains, I want to override this with my own.

2
  • If you have the other directories in subdomains then wordpress should not have anything to do with them. The setting is not clear please edit and clarify what is your setting and what is the problem Commented Sep 15, 2014 at 14:17
  • No, it does not affect my subdomains, but rather my other directories on my domain (where WP is installed on the root). The problem is that my WP's 404 shows, and not my custom when using the .htaccess file posted. I don't want the WP's 404 at all.
    – PWL
    Commented Sep 15, 2014 at 21:58

2 Answers 2

3

When a URL is processed by Wordpress, its index.php script is loaded with the path to the requested page. Because in this case the index.php script is always found, a normal 404 error will never trigger (via ErrorDocument 404 …). If the requested URL does not match a page that WP knows about, WP will display its own "404" page.

Unfortunately, if WP processes a URL, there is no way to use a normal 404 page, bypassing the WP 404 page. This issue is documented at https://core.trac.wordpress.org/ticket/7592.

1

Edit your 404.php in your theme folder or add a 404.php in your child theme folder, so it contains your error message. It will not bypass WordPress, but it is the only way. However, if you want to gain some speed, you can go for a quick redirection to a static page by putting this content into the theme's 404.php:

<?php if (!defined( 'ABSPATH' )) exit;

header('HTTP/1.0 404 Not Found');
readfile( ABSPATH . '/wp-content/static/404.html' );
exit;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.