We have recently done a massive migration from a custom CMS to Wordpress CMS however want to figure out the right way to do 301 redirects from a situation where their previous URLs did not have any sort of date in the permalink but new one does

Old permalink: /category/subcategory/1234/slug (1234 = post id)

New permalink: /category/subcategory/YYYY/MM/DD/slug

What is the best way to do 301 for over 60k articles that follow this structure?

1 Answer 1


Generally, you can use .htaccess (a file located at the root of the folder you are serving) and a regular expression to do the redirect. I used Yoast to generate mine:

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(?!page/)(.+)$ https://example.com/$4

In the regular expression above I match anything at the beginning then I match / followed by 4 digits (a year) followed by / followed by 2 digits (a month) followed by / followed by 2 digits (a day) followed by the page slug. $4 points to the 4th variable in (...). See here for explanations.

In your example, though, you need to retrieve the date information given the post identifier. In this case, you may find it easier to use a Wordpress plugin that will handle the redirection for you. This one (top result in Google) should do the trick.

PS: SEO best practices recommend moving away from date-based URLs. I am in the process of doing just that on my own sites. What's your reasoning for going the other way?

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.