WordPress.org

Ready to get started?Download WordPress

Forums

Redirecting 404 errors to 410 (18 posts)

  1. Jewelsnorth
    Member
    Posted 4 years ago #

    I'm setting up a job site and periodically want to delete old posts with expired listings.

    Is there a way I can redirect 404 errors to 410 pages, without explicitly placing the url in .htaccess file?

  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    You'd need to at least store the old urls to know what URLs require a 410 ... without knowing which URLs to 410, i can't see how you'd possibly do it..

    At a minimum you'd need to retain some record of deleted post urls .. (i believe) ...

    Not like anything i've dealt with personally though, so just my opinion.... :)

  3. Samuel B
    moderator
    Posted 4 years ago #

    good website practice would redirect 404's to a visitor site map IMO

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

    That could depend what they request... :)

    If a user requests UNION, EVAL or anything of the like, i'd rather send them somewhere less pleasant then a site map page.. ;)

  5. Jewelsnorth
    Member
    Posted 4 years ago #

    If I could get the 410 error to work in the .htaccess, I'd add a another statement: ErrorDocument 410 /410.php

  6. Samuel B
    moderator
    Posted 4 years ago #

    410 help
    http://diveintomark.org/archives/2003/03/27/http_error_410_gone

    help using mod_rewrite near bottom of page

  7. Samuel B
    moderator
    Posted 4 years ago #

    If a user requests UNION, EVAL or anything of the like, i'd rather send them somewhere less pleasant then a site map page.. ;

    haha - good point

  8. Mark / t31os
    Moderator
    Posted 4 years ago #

    ErrorDocument 410 /410.php

    What else are you doing other then setting the error document? That line alone just sets which document handles that given error.

    Which .htaccess file are you referring to, the one in the root? Is WP in the root also?

  9. Jewelsnorth
    Member
    Posted 4 years ago #

    I tried this (without the error document which I haven't added yet):

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{LA-U:REQUEST_FILENAME} !-f
    RewriteCond %{LA-U:REQUEST_FILENAME} !-d
    RewriteRule (.*) - [G]
    </IfModule>
    # END WordPres

    but it called the rewrite rules before the request is mapped to the file system to the value contained in REQUEST_FILENAME is the same as REQUEST_URI. This always fails and gives me a 410 for all the pages/posts except for index.php.

  10. Mark / t31os
    Moderator
    Posted 4 years ago #

    I'm not sure exactly what i'm suppose to be looking at here, are you modifying the WordPress rules shown above, i don't remember there being look ahead assertions there before...

    REQUEST_FILENAME and REQUEST_URI are usually the pretty much same, what are you expecting them to be? ..

    http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond

    Apache isn't me biggest area of experience, but i'd do my best to understand and help if i can... ;)

  11. Jewelsnorth
    Member
    Posted 4 years ago #

    I'm not sure either. The .htaccess exerpt I got from someone else and wasn't necessarily applicable to a WordPress environment.

    What I'd like to occur is that instead of getting a 404 error for any posts are deleted, can a 410 error be generated (and ideally the request redirected to a custom 410 page or even index.php).

    Is this possible?

    Edited to add: Someone on another forum unfamiliar with WP mentioned that

    because articles are generated dynamically, the !-f test (which checks if the file actually exists on the hard drive) will always be false (or true, if it is looking for the article-creating file).

    The workaround might be to hack the error document that is being served. You can alter the file so that if the request is for a deleted article, it sends a 410 error message instead of a 404 message.

    Does this seem reasonable and what might this look like?

  12. Mark / t31os
    Moderator
    Posted 4 years ago #

    Quite possible yes...

    The problem as i see, is you need a way to distinguish between when a 404 is a regular 404, and a non-existent post 404, as is, the server has no way to know the difference, to get around that problem you'd need to write some custom code to do it..

    However unless you're storing the URLs of deleted posts somewhere, then you'll have nothing to conditionalise your code against.. how would the server know the difference?.. Apache, PHP, WordPress can all do amazing things, but i don't think either of them will be able to psychically know which URLs to 410 and which to 404....without keeping a record of the old urls for it to compare against..

    Perhaps i'm misunderstanding or even over-thinking it... do you see what i'm getting at though?

  13. Jewelsnorth
    Member
    Posted 4 years ago #

    t31os_, that makes sense. :) I wasn't thinking about WordPress intuitively knowing which should be 404s vs. 410s, but rather simply assuming that any 404 should be a 410.

    The board will have job posts that get stale after a certain date. I don't want to leave the posts archived because job seekers get frustrated looking finding outdated entries. Likewise, deleting everything old and leaving 404s would only be accepted by search engines for just so long before I'd be penalized.

    Where I'm going I'd be thinking of using a hacked together "404-type page" for 410 redirects so I can still give readers a list of similar options.... if I can get the 410 redirect working that is.

  14. Mark / t31os
    Moderator
    Posted 4 years ago #

    You could just set the post status to draft, and it'll disappear from view..

    You'll still have them present, but it'll solve the problem of users seeing them.. (it's possible to filter them from the backend to)..

    I can't think of any other "easy" way to handle it..

  15. Jewelsnorth
    Member
    Posted 4 years ago #

    If I set a post to draft it turns into a 404, would it still they remain indexed by search engines and generate errors?

  16. Mark / t31os
    Moderator
    Posted 4 years ago #

    So keep track of the old urls (you'll have to figure how to go about doing this), then use a 404 template (see default theme for example) and have php check the referrer url against a list of known old(removed post) urls, and redirect appropriately from there....

    I can't see how it could be any easier then that.. short of just letting 404's occur and losing google juice from missing urls..

  17. Jewelsnorth
    Member
    Posted 4 years ago #

    Hmm, I'm wondering if it might work to use a Post Expiration plugin to move the posts into a new category after a period of X days. Then set the sitemap to Noindex that category.

    It would require a bit more processing on the server side, but would that cause the old links to drop from the search engines when they're next crawled?

  18. Mark / t31os
    Moderator
    Posted 4 years ago #

    Yes that should work in my opinion, i wouldn't know for certain in totally honesty though, but the idea sounds good...

Topic Closed

This topic has been closed to new replies.

About this Topic