Blog Post default image

If like me you are a bit of perfectionist when it comes to your web-sites and their SEO value, then you may eventually run into this problem.

You have gone to the effort of creating a nice .htaccess file for apache which removes the extensions of your webpages so you get nice pretty urls like

Pretty urls example
{code type=html}

www.mysite.com/subsection/
www.mysite.com/subsection/page


www.mysite.com/subsection/index.php
www.mysite.com/subsection/page.php
{/code}

See this post on how to create those pretty urls above
How to make pretty seo urls via .htaccess

You may also have installed WordPress or may be using it the way I do via an include header

The Problem
{code type=php}
define(‘WP_USE_THEMES’, false);
require($_SERVER[‘DOCUMENT_ROOT’] . ‘/blog/wp-blog-header.php’);
{/code}

Then one day you spidered your own site to make sure Google could index you correctly, all of a sudden you may have been surprised to find all your pretty urls, returning nasty 404 page not found errors in the header of your requests, even though you can browse to them and there are no apparent connection issues.

Well guess what is happening?

Simply put, WordPress does not like being included, they state quite publically you should use WordPress as a CMS and integrate your whole site into it. But stuff that for a joke, WordPress is slow and cumbersome and for many projects it just does not fit to make it control the entire site architecture. So many developers plug it in as a blog under it’s own section ie /blog/ or something similar. But WordPress then hijacks our pages and returns 404 errors on anything that does not live within it’s own structure.

That’s right, WordPress is the root cause of your 404 issues. But there is a simple fix I developed to keep using WordPress and not have it hijack your headers.

The Fix
{code type=php}
// Very simple php override header
// Place it straight after the WordPress include code
header(“HTTP/1.0 200”);
{/code}

Notice the last line, we simple reset our headers to always be a 200 OK response, no more stupid 404 errors just because you didn’t build your site 100% in WordPress. It won’t mess with your other headers either, if a page is not found it will still return a 404, this simply states that if my page exists, send a 200 response, it really just undoes the damage WordPress does.

The final code
{code type=php}
/* Short and sweet */
define(‘WP_USE_THEMES’, false);
require($_SERVER[‘DOCUMENT_ROOT’] . ‘/blog/wp-blog-header.php’);
header(“HTTP/1.0 200”);
{/code}

Enjoy!

Comments are closed.