Keeping traffic flowing to your WordPress site after a big restructuring
Any website which is around for more than a couple of years will probably go through some kind of restructuring – perhaps as part of getting a new theme, or reorganising and refining content for clarity and usability.
Often this sort of process involves changes to the urls (“permalinks”) used to access individual posts and pages. When this happens it’s really important to make sure that old links still work.
Firstly it’s a pretty bad experience if someone bookmarks a specific post, or lands on your site through a link from an external site, only to be greeted with “page not found”.
Secondly, it’s not going to help your Google ranking much if lots of incoming links and long-standing pages suddenly disappear. The content of your site might be basically the same, but if all the urls are different then as far as Google is concerned it might as well all be totally new content.
Luckily, WordPress is pretty forgiving…
WordPress is designed in such a way that it will do its best to let you change the urls of posts and pages fairly freely. Posts and pages are handled slightly differently:
By default the urls of posts look something like
http://www.mysite.co.uk/?p=23, but many WordPress users chose to use a prettier url format which includes the name of the post, for example:
http://www.mysite.co.uk/2015/01/29/my-awesome-post/. The url format of posts can be changed through the Settings > Permalinks menu.
The last part of the url in that example is referred to as the ‘slug’ and is created from the title of the post when it’s first saved. The slug doesn’t change if the post’s title is later updated, but can be edited through the “permalink” section below the post title on the edit screen.
Rule 1: Editing Post slugs doesn’t break old links
If you edit the post slug, WordPress will magically remember the history and redirect old links to the new url. For example:
If we start with a page called
and then change the slug so that the url of the post is now
then both links will work. You can even change the slug several times without breaking any old links.
Rule 2: Editing Post url structure (the permalinks) doesn’t break old links
Similarly if you change the permalink structure from
http://www.mysite.co.uk/my-post/ then both links will still work.
Rule 3: Changing both the permalink structure and the slug will break old links
It looks like WordPress can’t handle this:
http://www.mysite.co.uk/2015/01/29/my-post/ won’t automatically redirect to
Page slugs are set and edited in the same way as post slugs. The url structure of pages can be changed by making one page the “parent” of another.
Rule 4: Editing the parent/child relationships of pages doesn’t break old links.
If we start with a page called
and then restructure our site – we make ‘cars’ a child of ‘products’ so the url becomes:
then WordPress can easily redirect old links to the new page.
Rule 5: Editing the slugs of pages will break old links
However, if this gets changed to something like:
then WordPress has no way of associating the old link with the new page, and users of the old link will get a ‘404 – not found’ page.
So what do I do if I need to change my urls?
There are often good reasons for changing your page or post urls in a way which breaks old links. Fortunately it’s easy to make sure that users can continue to get the right content on your site.
The first thing to do before making any edits is to take note of some of the affected page or post urls – that way you can confirm whether or not they still work after you make your changes.
You can then use a plugin to manually redirect pages. There are a number of these on the directory (the Redirection plugin is popular). You simply tell the plugin for example:
And you’re done!
A more technical approach
If you have direct access to your servers and you’re happy messing about with them then it might be best to implement these redirects outside of WordPress altogether.
The best place to do redirects is in your web cache if you’re using one (eg Varnish), so the redirect happens before it even hits your web server. Failing that, putting the redirects in your web server configuration files will keep your WordPress installation blissfully unaware that any redirections are happening.
These approaches work best if setting up the redirects is an infrequent task – for example if you have a large set of redirects which need to be applied only once as part of restructuring your site.
A final thought
Editing the slug of a page feels like a small act and a quick way to make a link nicer, but it breaks any links which were previously pointing at that page. Even if you update fix your internal links, any links pointing to that page from other sites will no longer work. This is a common mistake which catches people out.
The main thing to remember is that you don’t have control over how people are getting to content on your site: if a page is publicly viewable, you should always consider the possibility that someone has copied the url and linked directly to that page.