Changing Permalinks Without Losing SEO or Social Shares

It was one of those harrowing mornings today when I took the plunge and changed the Wordpress permalinks on my main website of several thousand posts. And I did so without losing ground with Google - and without losing likes, tweets, or +1's.

Sponsored Links:
Sponsored Links:

I couldn’t stand looking at those old, ugly dates in my posts any longer. So instead of accroya.com/2014/03/11/postname I would now only see accroya.com/postname.

There are reasons to do this, the most important of which is that content with a date in the url “looks” old – even if you’ve updated it recently. See this article for more reasons to kill those dates in your link structure. So that article you refine every other month still looks two years old because of that pesky permalink created the day it was published. And many impatient Google searchers will skip right past that “old” post of yours.

I admit that part of my reason for writing this is because I’m afraid I may have to do it again one day and don’t want to have to duplicate what I just did.

To make things simple, here is what you have to do in order to change permalinks without losing any ground with search engines or social shares.

  • Generate some redirect code and drop it into your htaccess file
  • Switch your permalinks
  • Drop in some code to retain your social shares

Sounds easy.

Generate the Redirect Code

First up, let’s generate that redirect code. At first I thought had to put redirect code for every article, but that’s not the case. It’s a single line, which will look something like this:

RedirectMatch 301 /\d{4}/\d{2}/\d{2}/(.*) http://accroya.com/$1

You can generate your own code here.

Note that Google will not penalize you for a bunch of 301’s when restructuring your website.

Edit htaccess

There are a couple of ways to edit your .htaccess file. You can log into your server via FTP, or you can edit it with a plugin such as the Yoast WordPress SEO. Put the code generated above at the very beginning of your htaccess file. It work fine there for me.

Change Permalinks

Now that you have your redirect in place, you’ll want to go into Settings>Permalinks and set it to “Post name” and hit save.

At this point, your old clunky url’s should now be redirecting to your sleek new name-only permalinks.

permalinks

Sponsored Links:

Retaining Social Shares

Despite your beautiful new permalinks, you may have noticed that your social shares – Facebook likes, tweets, and Google +1’s – have all been reset to zero. On my main website, I had posts with thousands of shares, so to lose this was completely unacceptable – especially because Google clearly factors social shares into its search results.

I have to thank Dave Ward at Encosia for posting the solution to this problem, but – not being the tech type – it took me some time to figure out how to get it to work properly.

Because I was changing to and from the same structure he used in his example, I figured I could just change my URL and the code would work. It didn’t.

After several re-reads, I realized I had to change the sharing code as as well. And Mr. Ward didn’t post the method for changing Facebook or Google Plus, so I was on my own there. He also said he placed his in the single.php file, but that’s only because this is where his social buttons were. Mine were in their own php file, so I dropped the code in that file.

My social sharing code for Facebook, Twitter, and Google+ is below, and the parts I added are highlighted in red:

<div class=”share-button”><div class=”fb-like” data-layout=”button_count” data-action=”like” data-show-faces=”true” data-share=”false” data-href=”<?php echo $sharing_url; ?>”></div></div>

<div class=”share-button”><a href=”https://twitter.com/share” data-url=”<?php echo $sharing_url; ?>” class=”twitter-share-button”>Tweet</a></div>

<div class=”share-button”><div class=”g-plusone” data-size=”medium” data-href=”<?php echo $sharing_url; ?>”></div></div>
</section>

Once I added the above code and put it right before my social sharing code, everything worked.

I will say that I performed these tasks first on a test website to make sure it worked and that I knew what I was doing. This also made the task on my primary site go very quickly and smoothly.

The only problem I’ve encountered is that when I change the date of a post, my social shares also seem to reset. This could be due to caching or something else I haven’t discovered yet.

If you’ve found the instructions above help, let me know in the comments below. And if you have any additional fixes, comments, etc, please share!

Leave a comment

Your email address will not be published.


*


Are you human? * Time limit is exhausted. Please reload CAPTCHA.