START here

Permalink change – Website optimization [07]

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, I 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 the “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: “io.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: “io.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 the 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 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, instead 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 conclusion is that the first option makes the 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: “io.bikegremlin.com/6768/”. Very convenient for posting links on Twitter, or Instagram, for example.

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


A Downside:

In case of switching to a different CMS, you need to make redirections for every article. It’s highly impractical to “artificially hack” the “post-ID” into a new platform. That’s the biggest long-term downside of this permalink structure.


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 the F12 key and choosing the “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 – The 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 the 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: WordPress plugins (like Yoast, and The SEO Framework) automatically place 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 of 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 some extra long time. Sometimes as much as 2 seconds. Redirects are permanent (301), so the 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 because 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.

Update: I ran a series of tests using my new website speed testing method (explained in that link).

  • Test site 1 (TS1) was using permalink structure “www.test.com/post-id/post-name”.
  • Test site 2 (TS2) used “www.test.com/post-name”.

I did three series of tests using the GTmetrix page speed measuring tool.

  • First test series (PG 1) tested load time of one post.
  • Second test (PG 2) measured load time of a category listing, containing around 20 posts.
  • Third test (PG 3) tested a single post load time, but with all the cashing disabled (both server side and on Cloudflare).
Page load times with post id (TS1) vs post name (TS2) permalink structure
Page load times with post id (TS1) vs post name (TS2) permalink structure
Picture 6


The results I got are within a statistical error of my testing method. Apart from the first test: PG 1, where post-id structure (TS1) is a bit faster.

Posts load quickly on the well-optimized sites, on a good server. So I wanted to do some load tests, simulating more visitors, to see if there’s any difference. For that, I used the OctoPerf tool.

  • First two tests simulate 50 visitors simultaneously browsing the website, page after page.
  • Third test is done using 10 simulated visitors, but with all the website cashing disabled. Testing with 50 users and no cashing resulted in too many errors for average page load times to be measured (though website using post-ID permalink structure had some 10% fewer errors).
Load tests of websites using post-ID (TS1) and post-name (TS2) permalink structure
Load tests of websites using post-ID (TS1) and post-name (TS2) permalink structure
Picture 7


Differences are again really small (within the test method’s margin of error when cashing is enabled). Detailed load test results in .pdf:


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 the 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 structures 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.

Update: with updated results of my comparative speed tests, on a more powerful hosting server, speed differences are insignificantly small. There are other things that affect load speed a lot more than the permalink structure (like types of plugins used, caching etc.). However, I’d say that if the number of visitors rises so that the hosting server is more highly loaded, “www.test.com/post-id/postname” permalink structure is still a bit faster than “www.test.com/post-name”.


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.  🙂

2 thoughts on “Permalink change – Website optimization [07]”

  1. I’ve been testing this permalink structure over on my site at https://www.mealplays.com/

    What do you think about using the structure %postid%/%category%/%postname%/?

    It still seems to load just as fast and you can also use the “short url” version with just the post ID in the URL, like this: https://www.mealplays.com/359/
    which loads: https://www.mealplays.com/359/recipes/simple-marbled-cheesecake-recipe/

    I feel that having the category in the URL gives Google some SEO context, but retains the speed and other benefits of using the post ID at the start of the URI.

    • Hi Martin,

      You’ve made a very good point. That solution could be regarded as a win-win, from one angle.

      However – and this is mainly my “thinking out loud,” I don’t think anyone really knows how Google does the ranking exactly:

      For all I know, the further from the left a (key)word is, the less “weight” it has. Hence, it makes sense to have the “marbled-cheesecake-recipe” be closer to the left (preferably, right after the domain name, unless you decide to utilize the article ID and extra speed and linking options it provides).

      Also, Google should be able to understand the website’s structure from the provided sitemap(s), and by making indexes of all the category pages.

      Finally, it’s the page’s title, headings and, of course (probably most important) content that make by far the greatest impact (when it comes to on-site SEO, at least in my opinion).

      That’s one of the reasons why I chose to not use the category in my permalink structure. Another reason is that I prefer shorter links. Yes, we usually share them by copy/pasting, but I still prefer for them to be short and descriptive, so when I look at an URL, I get the idea of where it leads.

      Again, this is my opinion, based on my knowledge, education and experience. Different people have different experiences, and different opinions. I’m not making a living from “doing SEO” professionally.

      Relja

Comments are closed.


Please use the BikeGremlin.net forum for any comments or questions.

If you've found any errors or lacking information in the article(s) - please let me know by commenting on the BikeGremlin forum.
You can comment anonymously (by registering with any name/nickname), but I think it is good to publicly document all the article additions (and especially corrections) - even if their author chooses to remain anonymous.

Skip to content