最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

permalinks - How to 301 redirect from one url to another properly

programmeradmin1浏览0评论

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?

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?

Share Improve this question asked Jan 18, 2019 at 14:42 HossjHossj 1214 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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/$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?

发布评论

评论列表(0)

  1. 暂无评论