Missing pages return 200 codes instead of 404

Hi!

I’ve made a custom 404 page. WordFence Premium just audited my site and they wrote this:

One additional factor that I wanted to mention is that your site
appears to return 200 codes for missing pages. This can be quite
problematic when dealing with search; you do want non-existent pages
to return 404 codes. There is likely a configuration problem on your
server that your hosting provider should review.

I’ve talked to my host and they say they dont do script edits on the server for us but they sent this link: https://www.sistrix.com/ask-sistrix/onpage-optimisation/http-status-code/4xx-client-error-404-error-page/how-to-correctly-return-the-http-status-code-404-for-an-error-page/

I did change this Yoast thing to noindex:

I’m no wondering if my custom 404 page is returning 200 or 404? If 200, how do I fix it?

<3

A

Hello There,

Thanks for writing in! To make sure that you are returning the correct http status code as stated in the article, please do the following steps below:
1] Using Notepad or TextEdit or Sublime Text or any text editor, please create a new file in your local machine.
2] Insert the following code into that new file

<?php

// =============================================================================
// VIEWS/HEADER/BASE.PHP
// -----------------------------------------------------------------------------
// Declares the DOCTYPE for the site, includes the <head>, opens the <body>
// element as well as the .x-root <div> and .x-site <div>.
// =============================================================================

$x_root_atts = x_atts( apply_filters( 'x_root_atts', array( 'id' => 'x-root', 'class' => 'x-root' ) ) );
$x_site_atts = x_atts( apply_filters( 'x_site_atts', array( 'id' => 'x-site', 'class' => 'x-site site' ) ) );

?>

<?php if ( is_404() ) : ?>
    <?php header("HTTP/1.0 404 Not Found"); ?>
<?php endif; ?>


<!DOCTYPE html>

<html class="no-js" <?php language_attributes(); ?>>

<head>
  <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

  <div <?php echo $x_root_atts; ?>>

    <?php do_action( 'x_before_site_begin' ); ?>

    <div <?php echo $x_site_atts; ?>>

    <?php do_action( 'x_after_site_begin' ); ?>

3] Save the file named as base.php
4] Upload this file to your server in the child theme’s folder wp-content/themes/x-child/framework/views/header or wp-content/themes/pro-child/framework/views/header if you are using Pro theme.

You will have to create the folder path in your child theme because this does not exist yet.

Please let us know how it goes.

1 Like

That code worked for the 404 pages but it made my navigation disappear.

<3

Hey There,

The code should not affect the navigation. Please clear your cache first since you are using Endurance page cache and test your site again.

Please let us know if this works out for you.

Hi!

I’ve cleared cache, turned off WP Rocket and cleared cache again. The site still has no navigation.

Hey There,

Would you mind providing us with login credentials so we can take a closer look? Please provide following information:

Set it as Secure Note

  • Link to your site
  • WordPress Admin username / password
  • FTP credentials

All the best!

1 Like

Hi There,

Upon checking, I could not replicate the issue.

Could you please explain?

Thanks!

That’s because I couldn’t keep the code that made the nav disappear on my live site. I’ve now updated the secure note with login info to my dev site, http://dev.monroedesign.se. Please check it there. Please feel free to test stuff there.

Hello There,

I have commented the code and it does not affect or display any changes.

<?php

// =============================================================================
// VIEWS/HEADER/BASE.PHP
// -----------------------------------------------------------------------------
// Declares the DOCTYPE for the site, includes the <head>, opens the <body>
// element as well as the .x-root <div> and .x-site <div>.
// =============================================================================

$x_root_atts = x_atts( apply_filters( 'x_root_atts', array( 'id' => 'x-root', 'class' => 'x-root' ) ) );
$x_site_atts = x_atts( apply_filters( 'x_site_atts', array( 'id' => 'x-site', 'class' => 'x-site site' ) ) );

?>

<?php //if ( is_404() ) : ?>
    <?php //header("HTTP/1.0 404 Not Found"); ?>
<?php //endif; ?>


<!DOCTYPE html>

<html class="no-js" <?php language_attributes(); ?>>

<head>
  <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

  <div <?php echo $x_root_atts; ?>>

    <?php do_action( 'x_before_site_begin' ); ?>

    <div <?php echo $x_site_atts; ?>>

    <?php do_action( 'x_after_site_begin' ); ?>

I moved my testing in my local testing server and I can confirm that the navigation will not be displayed when you add the base.php file into the child theme. This is a bug in the theme. I have reported this to our developers already.

For the moment, I have renamed the base.php into ++base.php so that this will not take over the and still displays your navigation. We are now back to the issue that error 404 is returning 200.

I will also add this as a bug in the Custom 404 extension so that our developers will be made aware of it and hopefully resolve this in no time.

Thank you for your understanding.

1 Like

Hi Rue!

Thank you for going to the bottom with this issue. I see the file you added and I’ll just keep it there until I hear anything about an update of the Custom 404 extension then.

Thank you!

<3

Thank you for understanding!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.