I changed the permalink structure from /%category%/%postname%/
to /%year%/%monthnum%/%postname%//
How can I redirect all old posts to the new ones (eg: via htaccess)?
I changed the permalink structure from /%category%/%postname%/
to /%year%/%monthnum%/%postname%//
How can I redirect all old posts to the new ones (eg: via htaccess)?
You must be logged in to post a comment.
WordPress should handle the 301 redirects for you automatically in this case. It doesn’t always, but it should here.
Long story short, WordPress has a function,
redirect_guess_404_permalink
which tries to find the correct post when it encounters a 404 by using the end of the 404 url to query against thewp_posts.post_name
. If it finds a post, it will perform a 301 redirect. In your particular case, because your old structure ends in%postname%
, this should very reliably 301 all your old paths.You can also redirect via WP. Yes, the htaccess variant is with better performance, but a small plugin is easy to use.
Use the Hook
template_redirect
and check for the conditional functionis_404()
; if true, than get the right permalink and rewrite. Also you can use the small plugin Change Permalink Helper.