How to Change Your Blog’s Permalinks Without Losing Ranking

There may come a time where you would like to change your blog’s permalinks without losing ranking in the search engines. No longer having your posts appear in search results is probably one of the biggest fears of changing the permalinks for your posts.

When I started Technically Easy I used Google’s Blogger platform. The Blogger platform had many limitations, with on of the limitations being the structure of the permalinks to the blog posts. The limitation was that the author of the blog couldn’t change the permalink structure. All posts had the same permalink structure: “/year/month/postname”.

Back then I didn’t really care about the structure of the permalinks to my blog posts, and even when I switched to WordPress about a year later I didn’t think much about the structure.

Over the past few years, however, I started to think more about my blog posts’ permalinks and whether I should change them to just include the post name and not include the year and month. It wasn’t until recently did I decide to make the permalink change.

The good news is that once I change the permalinks on my blog, my traffic hasn’t decreased. The best part was changing the post permalink on my blog was actually easy and only took a few moments.

Below are the steps I took to change the permalinks on my blog. Keep in mind that the original links to my blog were in the form “/year/month/postname”, and if your is different you will need to determine what you changes you will need to make for your blog.

Change my blog’s permalinks

Changing my blog’s permalinks required two steps. The first step was setting up a redirect from the old permalinks to the new permalinks for each post. The good news is that this only required me to add one line to my .htaccess file on my Web host.

The second step was easy, I just had to change the permalink setting from within the WordPress admin site for my blog.

Let’s look at the first step.

Redirecting the old links to the new links

Out of the two steps to change the permalinks on my blog, this step is probably the most complicated. It requires some knowledge of using regular expressions to parse the old permalink to create the redirect to the new permalink.

To help illustrate how I went about making the change, I will use this post as an example.

The old permalink looked like the following:

http://technicallyeasy.net/2016/11/change-blogs-permalinks-without-losing-ranking/

The new permalink looks like the following:

http://technicallyeasy.net/change-blogs-permalinks-without-losing-ranking/

Basically what I want to do is to take the post name, and then just append it after my domain name, and remove both the year and month portions of the link.

To accomplish this, I added the following line to the end of my .htaccess file on my host:

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(.+)$  http://technicallyeasy.net/$3

This will probably look confusing to anyone not familiar with regular expressions, but I will explain what it does.

RedirectMatch 301
This is Apache’s command to redirect one URL to another, but unlike the Redirect command, this one uses regular expressions to determine the originating URL. The 301 is the indication that the URL is a permanent move, which will tell search engines that the new URL should always be used.
^/([0-9]{4})
This is the start of the regular expression. The ^ character indicates that the URL will start with the slash followed by 4 numbers – the year. This is indicated by the range [0-9] and the {4}. The parenthesis “( )” around this part of the regular expression allows this match to be used later by specifying $1 . The 1 indicates this is the first match.
/([0-9]{2})
This match is very similar to the previous one, with the one difference indicating it will match a 2 digit number – the month. You can see the same range [0-9] is used but this time it indicates only two digits with {2}. Once again, this expression is in a set of parenthesis so it can be remembered as $2.
(.*)$
There are three things used for matching in the last part. The first is the .* which will match a single character (.) zero or more times (*), which basically means everything will be matched. This is the actual post name, so any post name will be matched. The next part is to remember the match as $3, since it is surrounded by parenthesis. The $ indicates that only match if the previous is at the end of the string. Since the post name is at the end of the URL, it will be matched.
http://technicallyeasy.net/$3
This is where the new permalink is formed. I basically use the domain name of my blog and append the match from the post – the $3 from the previous item – and then append that value to the end of the domain name.

The above may seem confusing at first, and you are having trouble creating a regular expression for your permalinks, you can use Yoast’s Permalink Tool to help create the regular expression for to redirect your old permalinks.

Changing the permalink settings in WordPress

Once the redirect command is in .htaccess all the previous links will now redirect to the new ones, which will return a 404 – Page not found because WordPress is still setup to use the old permalink structure.

You will now need to fix this through your WordPress admin dashboard. You can use the following steps to change the permalink structure in WordPress:

  1. Log into your WordPress dashboard.
  2. From the options on the left click Settings->Permalinks.
  3. Under Common Settings select a permalink structure or create a custom one. In my case, I just clicked the Post name option.
  4. Click the Save Changes button to use the new permalink structure.

Once the above steps have been done, you old permalinks should now be redirected to the new permalinks without any issue.

With one command added to the .htaccess of my blog, and the permalink setting change in WordPress, I no longer have the year in month in my blog post permalinks. It is debatable as to whether this will have an effect on how my posts perform in search results, but regardless, I do like the more compact look of the permalinks.

Follow Me