When changing the permalink structure of your WordPress website, it’s crucial to manage your old links properly to avoid negative impacts on SEO and traffic. Unmanaged old links can lead to 404 errors, which harm your site’s performance.
In this article, we’ll guide you through changing your WordPress permalink structure without losing traffic or compromising SEO.
SCENARIO – 1
WordPress Permalink Changes with Redirection Using Regular Expressions
We’ll cover two common permalink structure changes: one from a date-based structure to a clean, simple format, and another from a random structure to a clean format.
If your website uses similar permalinks, you can simply paste the provided codes into a redirection plugin and save. If not, follow our detailed instructions to learn the entire process and implement it yourself.
Assuming your current permalink structure looks like this:
siteurl.com/2020/06/05/sample-post/
And you want to change it to
siteurl.com/sample-post/
You can redirect the old URLs by simply using the Regular Expression(RegEx) on the redirection plugin, like the graphic below…
So, how does this work? Let’s break down the code into human-understandable language. The code on the source target is …
^/[0-9]{4}\/[0-9]{2}\/[0-9]{2}\/(.*?)
- ‘^/‘ – This represents the domain like example.com/
- [0-9]{4}\/ – This represents the first four numbers, in this case, the year value in the permalink 2020/.
- [0-9]{2}\/ – This represents the month value in the permalink structure 06/
- [0-9]{2}\/ – This represents the date value in the permalink structure 05/
- (.*?) – This represents the sample-post . It captures the whole post-name of a group. You need this group to redirect the old links to the new structure.
For the target URL, you just need the group(sample-post) to be redirected to. In this case, we have only one group, so this group will be represented with $1. if we had more than one group then we should have to specify the exact group number( See SCENARIO-2).
So, on the target URL just specify the group /$1
. All the old links with the old URL structure with the date will now be redirected to the new URL structure.
In this process, your website traffic will be redirected and you will not break the SEO.
SCENARIO -2
Assuming the current permalink structure is like
siteurl.com/category/author/sample-post/
And you want to change it to
siteurl.com/sample-post/
You need to add regular expressions on the redirection plugin as in the image below. And read below for the explanation.
So, how does this work? Let’s break down the code into human-understandable language. The source URL code is …
^/(.*?)\/(.*?)\/(.*?)\
Here the source URL contains three groups (.*?)
. One is for Category, the second is for the author and the third is for the post name. The groups are separated by a forward slash(/).
And on the target URL, we only need the third group in this case. So the target URL is containing only the /$3
Do not forget to change the permalink structure to the Post name.
Final thoughts
Try to avoid changing the permalink structures more often. Because it can slow down the loading speed of the website if you frequently change the structure and create a new redirection rule each time.
If you face any issues, you can contact me for help. I will love to hear from you.
If you want to learn more about Regular Expression you can visit this website.