• 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?

Viewing 15 replies - 1 through 15 (of 17 total)
  • 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…. πŸ™‚

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

    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.. πŸ˜‰

    Thread Starter Jewelsnorth

    (@jewelsnorth)

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

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

    help using mod_rewrite near bottom of page

    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

    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?

    Thread Starter Jewelsnorth

    (@jewelsnorth)

    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.

    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… πŸ˜‰

    Thread Starter Jewelsnorth

    (@jewelsnorth)

    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?

    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?

    Thread Starter Jewelsnorth

    (@jewelsnorth)

    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.

    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..

    Thread Starter Jewelsnorth

    (@jewelsnorth)

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

    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..

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Redirecting 404 errors to 410’ is closed to new replies.