How I Changed WordPress Permalinks and Redirected Links and Updated Internal Links in Less than 15 Minutes

Share via email

What a title!

OK, for some reason I just decided that I did not want the old date structure for the site. It seemed a bit pointless. So in a rash move (2 glasses of wine) I changed the permalink structure to the good old tried and tested /%category%/%postname%.

I then thought, hmmm, must Redirect 301 the pages so Google does not leave people sitting on an error page. So I then decided to try to determine what the old URLs were…… (you can see that I did zero forward planning, again).

So this is what I did:

  1. I searched Google for site:webologist.co.uk sitemap – this led me to a cached version of my site index. Fortunately I keep all links on one page. So I viewed the Google cache, highlighted the links, right click and viewed selection source, copied, and pasted everything into an OpenOffice Calc spreadsheet.
  2. I then stripped all the junk from the results leaving just the URLs. This is how I did it, using simple Find and Replace:
  3. Each line started out like this: <li><a href=”/2009/08/10-key-seo-skills.html“><span>10 Key SEO Skills</span></a></li>
  4. First I replaced all <li><a href=” with blank so the line started with the URL. A good start.
  5. Then I deleted everything after the first ” with this command: “.* (ticking the “Regular Expressions” box in the More Options section). This left just the URL.
  6. I then copied the column of URLs to another sheet for safe keeping, as I was not done with these yet.
  7. Now that I had just the URL I wanted to strip it down to the new format. So I replaced the years, i.e. /2010 then back to the beginning, the first being /2006.
  8. Then I removed .html from each line (I actually did this first, but forgot to tell you. Makes no difference either way.
  9. This just left the URL in this format: /08/10-key-seo-skills
  10. That is the new resultant URL. What? with 08 as a category? Yes! WordPress is clever enough to redirect any “sub-directory” to the correct category for an article. So you can leave the months and they will help the redirect. To change them requires you to replace each one with the correct category, which turns a 10 minute job into a 10 hour job.
  11. So, back to that other sheet with the old URLs. Just do a find and replace for the domain, to leave the URL ready for redirect, i.e. /2009/08/10-key-seo-skills.html
  12. Now paste these URLs into the 2nd column of your first sheet, with the new URL in the 3rd column. Add Redirect 301 to the first column and copy down.
  13. Highlight all three columns and paste them into your .htaccess file.
  14. Upload, spot check.
  15. Next install the plugin Broken Link Checker.
  16. Force run it.
  17. Go to the results and choose all the Redirects. Highlight all (remove any affiliate links you may have!) and chose “Fix Redirects”. This will change all the internal links in your posts, pages and comments to the new format. You can take this opportunity to repair any broken links (I just unlinked all the external ones that are now broken, again, time saving).
  18. That’s it, job done.

I hope I did not forget anything there! The Broken Link Checker – http://wordpress.org/extend/plugins/broken-link-checker/ – is really good. It will also send you emails whenever it discovered a broken link. Great.

Fixing external redirects is something you need to be careful with really, as you may link to something like a-website.com/page and they may redirect to a temporary page for promotional purposes. If you fix the redirect and they change it again, it will break (unless they redirect properly, which rarely happens!).

With Broken Link Checker you can easily change the links from the admin area too, no need to go fishing in the files for those broken links.

So there you go. If at 1am after a couple of glasses of wine you decide to change the permalink structure of your WordPress blog, you can now complete the task in just 10 (or 15) minutes with no worries. So long as Google has cached your index page…

Right, time to install the automatic Google Sitemap plugin to help prompt the big G to sort out the mess I created in its index. Sorry Google!

Tags: