Update WordPress permalinks easily without losing SEO

Published 14 Dec 2019 in Blogging, ClassicPress, Marketing, SEO, WordPress by ZigPress

These days SEO experts recommend that the permalinks for WordPress and ClassicPress websites are set to ‘post name’. If you have an older site then you may have chosen a different permalink structure. Now you want to change it, but you’re worried about losing precious SEO indexing.

There are good reasons for choosing ‘post name’ for your permalink structure. It keeps URLs as short as possible while still conveying meaning and keeps URLs free from useless information. It also stops people being discouraged from clicking a search result if they see an old date in the URL.

But if you suddenly change your permalink structure, what happens to all those old URLs that have already been indexed by Google? Well, they will throw a 404 error. Not good. All that hard work wiped out in a stroke.

Note: if your old permalink setting was ‘Default’ or ‘Category – name’ then you don’t have to do anything at all – WordPress will handle the redirects automatically.

The hard way to update your permalinks without losing SEO

After changing your permalinks on the permalink settings page, you could install a redirection plugin (there are several good free ones) and manually add entries for all the posts that have been indexed by Google. So each redirect entry would be something like this:

FROM: https://www.zigpress.com/2018-04-15/this-is-the-post-title/
TO: https://www.zigpress.com/this-is-the-post-title/
TYPE: 301

This will work but if you have a lot of posts, this is a long, tedious, task.

The easy way to update your permalinks without losing SEO

If your web host is running Apache (in other words, if the .htaccess file is used on your site), there is a much easier way.

Step 1

Install and activate our free plugin ZigHtaccess which will let you edit the content of your .htaccess file. It’s compatible with both WordPress and ClassicPress. Here’s the link to the ZigHtaccess page in the WordPress plugin repository.

Step 2

Go and change your permalinks to ‘Post name‘ after making a note of what they were set to before (for example, ‘Day and name’ or ‘Numeric’).

Step 3

Use the ZigHtaccess editor page (reached from ‘Settings’) to add a line of code at the top of your .htaccess file. In each case below, replace www.mydomain.com with your actual domain name!

Please copy and paste carefully, since an .htaccess file with errors can break the front end of your site. And please ensure you add the line to the top of the .htaccess file, before any other lines in the file.

Note: if your site runs in a subfolder, scroll further down for the correct code.

If your old permalink setting was ‘Day and name‘, add this line of code to the top of your .htaccess file:

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

If your old permalink setting was ‘Month and name‘, add this line of code to the top of your .htaccess file:

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

If your old permalink setting was ‘Numeric‘, add this line of code to the top of your .htaccess file:

RedirectMatch 301 ^/archives/(\d+)$ https://www.mydomain.com/?p=$1
If your site runs in a subfolder

If your WordPress site runs in a subfolder (for example www.mydomain.com/blog), you need to amend the code as shown below. In each case, change the word subfolder to your subfolder name.

If your old permalink setting was ‘Day and name‘, add this line of code to the top of your .htaccess file:

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

If your old permalink setting was ‘Month and name‘, add this line of code to the top of your .htaccess file:

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

If your old permalink setting was ‘Numeric‘, add this line of code to the top of your .htaccess file:

RedirectMatch 301 ^/subfolder/archives/(\d+)$ https://www.mydomain.com/subfolder/?p=$1

Done

When you’ve added the correct line of code to your .htaccess file, save the changes and you’re done. Now test your site, and click some of your Google search results to make sure the redirect is happening. Once you’re happy that everything is OK, you can deactivate and even remove ZigHtaccess if you like – or you may decide it’s a useful plugin to have available. It’s up to you.

And in fact after a few months, once you’re sure that Google has caught up with your permalink changes, you can even use ZigHtaccess to remove the new line from your .htaccess file, since it will no longer strictly be needed.

If you need to reverse the process for any reason, simply remove the new line from your .htaccess file and save the changes, then go to the permalink settings page and switch the permalinks back to what they were before.

If you don’t feel confident doing this yourself, we’d be happy to help for a small fee – just use our Contact page to get in touch.

Disclaimer: This article and the ZigHtaccess plugin are offered without any kind of warranty, promise or guarantee, and the article and plugin author bears no responsibility for any problems or loss of code, data or income incurred as a result of using this article or the plugin.

7 Comments

  1. On 08 Jan 2020 at 18:30, Jeffrey Shepard said:

    Hi,

    Very nice article.
    Thanks for sharing.
    Keep up the great work.

    Thank you

  2. On 03 Feb 2020 at 23:50, Sadimageinboy said:

    Hello Sir, Thanks For The Nice Article And Great Information.

  3. On 03 Feb 2020 at 23:52, Money Source Guide said:

    Very interesting blog. Alot of blogs I see these days don’t really provide anything that I’m interested in, but I’m most definately interested in this one.

  4. On 03 Feb 2020 at 23:54, Latest Movie Download 2020 said:

    this blog is very nice thanks for sharing its very helpful data thank you.

  5. On 06 Feb 2020 at 13:36, Software Solutions said:

    Thanks for sharing such a wonderful blog like this ….its really helpful and easy to understand..great work..keep it up…

  6. On 16 Mar 2020 at 11:14, Denise Browning said:

    Great to know there is an easier way to update link structure. But if I leave that host or there is a problem with the host? Would this generate problems with the links?

  7. On 17 Mar 2020 at 14:10, ZigPress said:

    @Denise: no, that shouldn’t impact the links, as long as your htaccess file gets migrated along with your site when you move hosts.