Website optimization [07] Permalink change

Website optimization [07] Permalink change

Updated: 21/03/2019.

In this post I’ll deal with WordPress permalinks, their alteration/change on a “live” website and solving/preventing problems that it can cause. Using Google didn’t provide complete answers on this (not for me at least), so I did some testing on a test website, then tried on one “live” website, then another – finally sharing my experience and knowledge in case it could help someone else.

Contents:
0. Introduction and starting notes
1. What are WordPress permalinks
2. Post name and ID
…2.1. Post name
…2.2. Post ID
3. Best permalink structure
4. Automatic WordPress redirections
5. Speed
6. Page ranking, visitors and conclusion
7. Sources

0. Introduction and starting notes

Shortly: in my opinion and experience, the best WordPress permalink structure is: “domain/post-ID/post-name/”.
When changing the permalink structure, WordPress automatically handles all the needed redirections. However, it is advisable to edit all the internal links, so the visitors don’t have to go through redirects when clicking on your website links.
Of course (and unfortunately), there are some things to consider and they’re all explained in this post.

Disclaimer: I am by no means a WordPress expert, in fact have no idea what is “below the hood” – all my testing was done using a “black box” method. In those terms, any additions and/or corrections are more than welcome, but please provide an explanation of how to replicate the test(s) and confirm your claims. Also, use all the advice and info from this text at your own risk. Changing link structure always carries a risk of ruining a website’s functionality, SEO and search engine ranking. By all means make a website backup before any changes. Bottom line: this has worked perfectly for me and I have not yet found any reason why it should not work (in theory, or practice).


1. What are WordPress permalinks

Permalinks are “fixed” links of all the posts. That is, until you “manually” change a link to a published post, it remains the same.

Permalink structure is a predefined (chosen) way the permalinks are created when publishing new posts.

Both these terms are somewhat linked (pun intended 🙂 ) and will be clearer after looking at picture 1 and the explanation below.

WordPress menu for choosing permalink structure Picture 1
WordPress menu for choosing permalink structure
Picture 1

Picture 1 shows WordPress permalink options, with “Custom Structure” (last) option for making a user-desired permalink structure. This post has a “slug”, or “post name”: “permalink-change“.

My chosen permalink structure is “Custom structure”, with “post_id/postname”, so it shows in your browser as: “bikegremlin.com/6768/permalink-change/”.

Up to a few months ago, chosen permalink structure of this website was “Day and name”, so the link of this post would have been for example: “bikegremlin.com/2018/12/07/permalink-change/”.


2. Post name and ID

Before explaining optimal permalink structure and redirections, it is important to explain these two terms: post name and post ID number.

2.1. Post name

When creating a new post, WordPress will automatically generate the post name – based on the post’s title. Of course, this can be edited/changed.

“Manually” changing post name Picture 2
“Manually” changing post name
Picture 2

There is an important “catch” though: WordPress won’t allow creation of several posts with identical post names. So, if you make a post named “hello-world”, then try to make another, WordPress will automatically change it to “hello-world-2”, with additional ones named the same ending with “-3”, “-4” and so on.

So post name is unique. There are no two posts on a WordPress website with an exactly the same post name. This is important to note in order to understand redirections, as will later be explained.

WordPress automatically does a search on post name, so if you type in your browser: “io.bikegremlin.com/permalink-change”, you will get this post, that is you’ll be redirected to: “io.bikegremlin.com/6768/permalink-change/”. That’s not all, but more on that in chapter 4.

2.2. Post ID

Each post automatically gets its unique ID number (ranging from one t N digits). Unlike post name, this is not meant to be changed by the user, it is fully automated and “fixed”. My educated guess is that this is the unique key and WordPress database index.

Similar to post name, WordPress can use post ID to look for a post – so “io.bikegremlin.com/6768” also takes you to this post, even though the website permalink structure is different. However, in order for this to work, it is necessary to place post ID at the first place in the chosen permalink structure (website/post-ID/whatever).


3. Best permalink structure

Bikegremlin.com had permalink structure: year/month/day/post-name. For some unexplained reason I had thought that was a good idea when setting up the website (“yaaay, I’ll have all the posts sorted by date of writing…” myes. 🙂  ).

In time I had realised that is a pretty bad choice. Why? Reasons listed by importance:

  • Having a post ID at the “root” of the permalink structure, in stead of a date, or something else, results in the fastest possible database search, hence a bit “faster website”.
  • Including a date makes a longer link, which is generally not good – the shorter the better.
  • Post publishing date is already shown once you “open” a post and since this is not some daily news website, it is much less relevant than the “last updated” date.

What is the best permalink structure then? I’ll write the “most often” found opinions, as well as my opinion & conclusion, so you can decide for yourself what is the best choice for you.

  • Many claim that, from SEO perspective, the best permalink structure is: website/post-name. This is true in terms that important keywords are closer to the URL beginning, so they “carry” more “weight” for the search engines.
  • Similar view point is that post category should also be included, if its name has a great SEO value. Downside of this is longer links.
  • In addition to this, some claim that having category before post-name in permalink structure helps search engines figure out website’s structure. This is completely false in my opinion & experience, if site-maps are made and given to search engines (and I see no reason not to do so). Only valid argument for categories in links is the keywords – this depends on website type, but for most it is just a needless/harmful extra.

My conclustion is that the first option makes most sense, with two downsides:

  • More time/server load when searching the database by the name – at least with WordPress.
  • No easy way of making shorter links.

So I chose:
bikegremlin.com/post-ID/post-name.

This allows for the fastest possible database search (and website performance) and I can easily create short links, like for this post: “bike.bikegremlin.com/6768/”. Very convenient for posting links on Twitter, or Instagram, for example.

How I “painlessly” changed the permalink structure to this, current one, will be explained in the next chapter.


4. Automatic WordPress redirections

This is, at least for me, the most interesting part – how WordPress handles redirections, especially in case of a permalink structure change. First a short introduction.

In many places I read how to set redirections by editing .htaccess file on the server, or using plugins.

Had I just wanted to exclude dates from URL-s, there would have been no problem writing a redirect rule that just excludes them from all the links (shortly and simply put). But I wanted to include a unique post-ID. Since there’s no rule that I know of for choosing a post ID, so I’d have to write a separate redirect rule for each published post (well over 100).

Hence I started experimenting with redirects that WordPress does automatically. Now, remember chapters 2.1. and 2.2. about post names and IDs, i.e. that WordPress can make an automatic search for those. I looked into that. Using Google Chrome browser, pressing F12 key and choosing “Network” option, you can see the traffic when browsing, see what goes on. I played with that a bit and came to info about permanent (301) redirects that WordPress makes – just like I needed it to.

WordPress redirect – Network part shows the 301 redirect, while the header shows the address where the redirect was made to – just where it was needed. Picture 3
WordPress redirect – Network part shows the 301 redirect, while the header shows the address where the redirect was made to – just where it was needed.
Picture 3

So, WordPress looks over the given link and if it sees a post name included – redirects to that post. It is even enough to give it just the first letter, or two – it will redirect to the first post (alphabetically sorting post names) with a name that starts with those letters. In my case, old links did have a date included, but also had full, correct post names – so automatic redirections were done without any problems – directly to the relevant posts with a new permalink structure, as you can see from picture 3. I just entered: “bike.bikegremlin.com/winter”.

Exceptions?

If a permalink structure is chosen using post ID at some position – in my case it was just after the domain name (bike.bikegremlin.com/post-ID/post-name/), then WordPress will redirect to the post with that ID number – as long as the ID number exists. If the given ID number doesn’t exist, WordPress searches by post name, as was explained just above.

WordPress redirects to a post with the given post ID, even though the given post name is a non-existing one Picture 4
WordPress redirects to a post with the given post ID, even though the given post name is a non-existing one
Picture 4

Another nice thing about the permalink structure I chose is it enables simple making of short URL-s, by just entering post ID behind the domain name. For example: “bike.bikegremlin.com/6740”. Just that post name doesn’t get included in the URL in that case. Picture 5.

“Abusing” a shortened URL Picture 5
“Abusing” a shortened URL
Picture 5

Fun fact: if you enter full domain name and post ID with a trailing slash, the page will be shown “directly”, without any redirects. For example:
“https://bike.bikegremlin.com/6740/”

Note: after a good question posted on wordpress.stackexchange.com, it should be explained: Yoast SEO WordPress plugin automatically places a “canonical” URL tag to each post, based on the current permalink structure. So no problems with duplicate content even with “multiple links” working for each post.

Anchor links are also no problem, as you can see by trying this link:
https://bike.bikegremlin.com/2016/06/08/bicycle-rear-shifter-compatibility/#Friction

It gets automatically permanently redirected to:
https://bike.bikegremlin.com/1339/bicycle-rear-shifter-compatibility/#Friction


5. Speed

Choosing post ID as the first part in the permalink structure has improved this website’s performance. Bikegremlin is now on a relatively weak host-server and server response time has dropped below 1 second for the first time (was about 1.2 on average, after all the previous optimizations).

Average redirect time did rapidly increase – from below 0.2 to over 1 second. Why? Because all the “old” links pointing to the website are now redirected, by WordPress, not the hosting server, which takes extra long time. Sometimes as much as 2 seconds. Redirects are permanent (301), so visitor’s browser remembers them for future use, but all the new visitors using old links for the first time are redirected – once.

In time, average redirect time did get faster, but not to the “old” speed. Because there still are new visitors coming to the site using the old links (forums, social network shares etc.).

That is why it is not advisable to change permalink structure without a very good reason and definitely not on a website that’s been up for long. In my case I decided the change needed to be made, better late than never, accepting all the negative consequences.

I did edit all the internal links to the new structure – so they at least don’t have to be redirected, not even upon the first visit. I did this manually, since I wanted to update old posts and check all the links anyway. So I joined the ugly, but necessary task with a useful one so to say.


6. Page ranking, visitors and conclusion

Here I didn’t see any drops and I think the new permalink structure is better for the future, that’s why I bothered to change it. Nothing else to add.

Conclusion:

Choose permalink structure wisely. For WordPress, taking both SEO and performance into account, with all the pros and cons, I think the best permalink structure is:
domain-name/post-ID/post-name/

If you must change permalink structure, better to do it sooner, than later. As I’ve explained, it has some downsides, takes some effort, but if you choose a “fast” permalink structure (as recommended in the previous paragraph), website performance should be better in the long run.

Most other places on the Internet give advice that contradicts my test results and experience. Recommending different permalink structure and/or saying that WordPress automatic redirects don’t work. But I’m yet to see a test that proves this. All my testing shows things written in this post are in fact correct.


7. Sources

Some of the listed sources contradict what’s written here. However, this has all been tested on 2 “live” websites and it works! In other words: I probably am crazy, but it doesn’t mean I’m wrong.  🙂

Leave a Comment