1

On my site, people can link to non-existing posts, which is fine because that's the whole structure on my site... The problem is that you get 404 errors, which is not good for SEO. Is there a way in Wordpress to avoid 404 pages? So if a post not exists, that you can do else instead of sending to Google that it's a 404 page?

8
  • 1
    A 404 is appropriate for a file that does not exist but what would you want to do instead? What is the "structure on [your] site" that makes you want to maintain broken links?
    – s_ha_dum
    Aug 7, 2013 at 20:27
  • Once, I had a PHP website without a CMS. On there, the non existing links were not outputting 404 errors, but were going to a page where you can add that particular post. Google did not saw it as 404 pages. But Wordpress does this as it's default. So I want to know if it's possible (if so, how) to make it something else... Does not matter what, just something else. Aug 7, 2013 at 20:31
  • So you have some kind of "front end posting" setup? You want users forwarded to a "create post" form for nonexistent post? Something like that?
    – s_ha_dum
    Aug 7, 2013 at 20:33
  • Exactly. But once again, it does not matter actually where it goes to, I will find something, so long it does not say to Google that it's a 404 page... It is affecting the SEO and that's very very frustrating. The site can't grow because of it. Aug 7, 2013 at 20:34
  • @s_ha_dum Is it possible? If no, would a redirection (301) of 404 pages be a solution for SEO? Aug 7, 2013 at 20:40

2 Answers 2

2

One way to do this is to use the status_header filter. Adding the following to the functions.php file or your theme (or an appropriate plugin file) would do the trick:

add_filter( 'status_header', 'your_status_header_function', 10, 2 );

/**
 * Substitutes a 202 Accepted header for 404s.
 *
 * @param string $status_header The complete status header string
 * @param string $header HTTP status code
 * @return string $status_header
 */
function your_status_header_function( $status_header, $header ) {

    // if a 404, convert to 202
    if ( (int) $header == 404 )
        return status_header( 202 );

    // otherwise, return the unchanged header
    return $status_header;
}

Alternately, you could add @header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 202 Accepted', true, 202 ); to your 404.php file before the get_header() call.

The downside to this is that all 404s will be returned as 202, including legitimate Files Not Found.

Users will still be served the 404.php template, so add your create post form there and you should be good.

5
  • This is what the OP wanted but I really do not think it is a good idea. I'd suggest at least sending a different header... perhaps 201, 204, 307, something besides "Everything is normal. All Good."
    – s_ha_dum
    Aug 7, 2013 at 22:43
  • I don't think it's a good idea either. A 404 should be a 404. Good thought on changing the response code. Do you think 201 or 202 is more appropriate? Aug 7, 2013 at 22:56
  • I would think a 202 personally, a 201 is supposed to indicate something was created by the request right? Aug 8, 2013 at 0:01
  • 202 would work too. I am improvising. There isn't really a header for "this page didn't exist when you tried to access it but we'll create one now so try again in a little bit".
    – s_ha_dum
    Aug 8, 2013 at 1:33
  • Wikipedia uses a 404 page in this instance, TVTropes uses a 200. I'm editing my answer to return 202. I don't think it's precisely accurate either, but my meager understanding of the specs makes me think it's the closest match for what we're doing here. Aug 8, 2013 at 2:04
0

Permalink Finder Plugin serves that purpose.

1
  • 2
    Does it really? The plugin's description indicates that it looks to find similarly-named pages/posts and redirects using a 301 header. The OP wanted to send back a 200 header and allow the missing page to be added.
    – Pat J
    Aug 8, 2013 at 2:44

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.