Custom 404 page not returning 404 status

#157879
  • Resolved Vadim Pavlovich
    Rank Math free

    Hello, how do I set a custom 404 page to actually return a 404 status?

    I have custom 404 page on my site, but it returns status:200.

    Few examples in the sensitive data box.

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,

    Thanks for contacting us and sorry for any inconvenience that might have been caused due to that.

    We are working on a fix to this problem with Rank Math not detecting the 404s when using custom 404 pages or templates.

    For now, please navigate to WP Dashboard > Plugins > Plugin Editor and select Rank Math SEO and go to /seo-by-rank-math/includes/modules/404-monitor/class-monitor.php

    One Line 45, change this:

    $this->action( 'get_header', 'capture_404' );

    To this:

    $this->action( 'template_redirect', 'capture_404' );

    That will fix your issue. In the meantime, we are also working on a better way to implement this solution without breaking certain templates.

    We will notify you when we have an update.

    Hope this helps. Let us know if you need any further assistance.

    I just applied this fix, but my custom 404 still returns 200 status.

    I will update sensitive data and add url to custom 404 page

    Here is piece of code I adjusted:

    
    		$this->action( 'template_redirect', 'capture_404' );
    		if ( Helper::has_cap( '404_monitor' ) ) {
    			$this->action( 'rank_math/admin_bar/items', 'admin_bar_items', 11 );
    		}
    	}
    

    Hello,

    Thank you for that additional information, and sorry for the delay.

    The 404 Monitor will only log a URL as 404 if it actually returns a 404 status. You can also check your URL status here: https://httpstatus.io

    Could you check your custom 404 page if the line below is already existing? If not, please try adding them in the header and check the status if it still returns 200.

    <?php
    header("HTTP/1.0 404 Not Found");
    ?>

    I hope that helps. Thank you, and looking forward to your update.

    I’m not really good at technical details – does this line needs to be added to 404 page php template?

    Thank you!

    Anas
    Rank Math business

    Hello,

    Yes, please add the code-shared by my colleague to the 404 page php template.

    I hope this helps. Looking forward to helping you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)

The ticket ‘Custom 404 page not returning 404 status’ is closed to new replies.