Changing the post date without causing 404 error

We have permalink structure based on date (like ‘www.mysite/2012/05/27/postname’).
Some times there are some posts that we need to be shown the first, so we change they date.
The problem is, that by this way, after changing the date the URL is chenged also, so the old link causes 404 error.
Is there any solution for this problem?

Related posts

1 comment

  1. You’ll need to add 301 redirects for the old URL to the new one. Your best bet is to do this via .htaccess, in your theme, or using a plugin like one of these:

    Edit: Another option

    OPtion 2 would be to disregard the date in the URI altogether. You could unset them from the request like so (add to your functions.php file):

    function wpse_100936_request( $qv ) {
        if ( isset( $qv['name'], $qv['year'], $qv['monthnum'], $qv['day'] ) ) {
            unset( $qv['year'], $qv['monthnum'], $qv['day'] );
        }
        return $qv;
    }
    add_action( 'request', 'wpse_100936_request' );
    

    Then the date can change and not cause 404s. A post can now be accessed at any date, e.g. /2013/05/28/some-post/ and /1776/07/04/some-post/. SEO experts might warn you of “duplicate content”, but the canonical meta tag will always point to the correct date, so that shouldn’t be an issue. The only potential issue I can foresee is that, if someone linked to the post at the old date, they won’t get redirected; whether that’s important or not is up to you.

Comments are closed.