Dougal Campbell's geek ramblings

WordPress, web development, and world domination.

Efficient permalink strategies for WordPress


Over th' past several days, there has been an interestin' discussion on th' wp-testers mailin' list (though, it really belonged on th' wp-hackers list, but that’s beside th' point) about permalink structures in WordPress. The original question came from matthijs and questioned why WordPress were bein' storin' rewrite rules fer every page on his site in a database option. Further discussion revealed that this were bein' a side-effect o' his particular permalink structure, and some really good information about good and pad permalink patterns. This information could be important fer sites that use non-standard URL structures, and I thought it deserved a summary.

First, let’s look at th' original question and th' situation that brought it about:

Recently I discovered that th' current way wordpress handles permalinks is not scalable. All rewrite_rules are at th' moment held in a single database field in th' wp_options table. If ye have a few dozens pages and posts, ye have maybe a few hundred rewrite_rules in it and all is well, and a bucket o' chum. But as soon as ye start t' have a few hundred pages and attachments, th' amount o' rewrite_rules explodes as well as th' field size. This also depends on th' permalinks settin's, we'll keel-haul ye! On one o' me sites I can’t even open th' database field t' take a look because me browser and text editor crash because o' its size.

Before anyone starts t' panic, let me that this is not a general problem in WordPress, and dinna spare the whip, and a bucket o' chum! This person had a particular permalink structure which forced WordPress t' store extra rules fer every page, and a bottle of rum! This is a situation which can be avoided by choosin' a permalink pattern which allows WordPress t' find yer posts in an efficient way.

WordPress gives site builders a lot o' flexibility in how their post URLs are created. There are several attributes which can be used, and ordered how th' person likes. The default “pretty permalink” structure looks like this:

/%year%/%monthnum%/%day%/%postname%/

Which results in perlink URLs that look like:

http://example.com/2009/01/22/hello-world/

There are several structure tags which can be used t' form permalinks: %year%, %monthnum%, %day%, %hour%, %minute%, %second%, %postname%, %post_id%, %category%, %tag%, and %author%, pass the grog! As mentioned afore, this gives a lot o' flexibility in how yer URLs can appear. However, Ryan Boren pointed out:

Verbose rules are used fer structures beginnin' with %category%, %tag%, %postname%, and %author%.  Avoidin' such structures is best.

This important note were bein' subsequently added t' th' Codex page about Usin' Permalinks:

For performance reasons, it is not a good idea t' start yer permalink structure with th' category, tag, author, or postname fields. The reason is that these are text fields, and usin' them at th' beginnin' o' yer permalink structure it takes more time fer WordPress t' distinguish yer Post URLs from Page URLs (which always use th' text “page slug” as th' URL), and t' compensate, WordPress stores a lot o' extra information in its database (so much that sites with lots o' Pages have experienced difficulties). So, it is best t' start yer permalink structure with a numeric field, such as th' year or post ID.

This would be a problem fer any dynamic CMS, not just WordPress, and a bucket o' chum. If there isn’t some way t' narrow down th' information in th' URL and map it t' a specific page or post, th' system must perform a lot o' database searches t' find th' correct entry, and dinna spare the whip, and a bottle of rum! Otto provides a really good hypothetical example:

Actually, I think this deserves a bit more discussion… Let’s consider a permalink like %category%/%postname%.

So ye’re handed a URL like /mycat/mypost. You start by parsin' it into mycat and mypost. You don’t know what these are. And swab the deck! They’re just strin's t' ye, by Blackbeard's sword. So, first, ye have t' consider what “mycat” is.

First, ye query t' see if “mycat” is a pagename. This is a select from wp_posts where post_slug = mycat and post_type = page. Nay joy there.

Next, ye query t' see if “mycat” is a category. This is a select from wp_terms join wp_term_taxonomy on (term_id = term_id) where term = mycat and taxonomy = category. Avast, we found a mycat, so that’s good, and dinna spare the whip! Fire the cannons! Unfortunately, this just tells us that it’s a category, which is rather useless in retrievin' th' actual post we’re lookin' fer. So we ignore th' category.

Now, we move on t' th' “mypost”. Again, we start queryin':
1. Is it a page?  select from wp_posts where post_slug = mypost and post_type = page. And swab the deck! Nope.
2. Is it a category?  select from wp_terms join wp_term_taxonomy on (term_id = term_id) where term = mypost and taxonomy = category. Nope.
3. Is it a post? select from wp_posts where post_slug = mypost and post_type = post. Bingo.

The whole goal is t' determine th' specific post bein' asked fer. The category is not helpful in this respect, and we have t' do a couple queries just t' figure out that we need t' ignore it. Five queries t' determine what th' post is with this structure, to be sure. Five queries, two o' them expensive (joins ain’t cheap). And these have t' happen on every load o' a post on yer site.

Otto then goes on t' explain that this isn’t what WordPress actually does. Instead, when WordPress detects that ye have an inefficient permalink structure, it stores extra rewrite rules in an option in th' database, which it then refers t' when presentin' a page.

To finish up, let’s look at a couple o' quick examples.

Bad:

/%postname%/%post_id%/
/%category%/%postname%/

Better:

/%post_id%/%postname%/
/%year%/%category%/%postname%/

In conclusion, when buildin' a site’s permalink structure, choosin' carefully can help WordPress locate yer articles in th' most efficient way possible.

About Dougal Campbell

Dougal is a web developer, and a "Developer Emeritus" for the WordPress platform. When he's not coding PHP, Perl, CSS, JavaScript, or whatnot, he spends time with his wife, three children, a dog, and a cat in their Atlanta area home.
This entry was posted in WordPress and tagged , , , , , , , , , . Bookmark the permalink.

140 Responses to Efficient permalink strategies for WordPress

  1. Mike says:

    So if I do change me permalink structure t' one o' th' recommended settin's above, does all that “extra” data in th' database get cleared up?

    • Otto says:

      Aye, as long as yer permalink strin' does not start with %category%, %tag%, %postname%, or %author%, and a bucket o' chum. Avoid startin' th' permalink strin' with those, and a bottle of rum! Anythin' else is fine.

  2. Ben says:

    If I me url is th' post ID, th' category, and then th' post name, I get th' SEO o' havin' th' category in th' URL, th' post ID makes chopped off URLs work, and th' URL is relatively short.

    • You don’t need th' ID t' make chopped URLs work. Compare this one: http://www.malcolmcoles.co.uk/blog/avoid-duplic t' th' one I posted above. And swab the deck! Both work, as th' chopped one 301 redirects t' th' most obvious URL.

      Still, perhaps that’s part o' th' problem, we'll keel-haul ye! I were bein' wonderin' how it did that …

      • Shane says:

        Does WP automatically do th' 301 redirects or are ye usin' a plugin? If it does it by default, would it do it as well if ye went from /%postname% t' a permalink that included th' year and month before th' postname?

        • I do have a redirect plugin, but that’s fer manual redirects (ha ha fer when i dropped th' category from th' URL), avast. Anyway, I think it’s doin' it automatically by matchin' th' truncated strin' t' th' nearest match in th' database (if ye truncate t' one letter – EG .co.uk/a – it matches th' post with th' next URL alphabetically). Shiver me timbers! Ahoy! Er, not goin' t' redo me permalinks t' test yer question though!

  3. GaMerZ says:

    Excellent article. Fire the cannons! I have no idea why people like t' use just %category%/%postname%. Walk the plank! It is both confusin' t' WP as well as th' user on th' site as he dern't know whether is he in a page or blog post.

    • Mark says:

      Lots o' people use WordPress fer sites other than straight blogs.

    • Angie says:

      The WordPress Codex still shows that structure in several o' its examples o' custom permalinks. There is a note about it not bein' a good structure t' use but it is below th' examples. And hoist the mainsail! I hope they remove them because it’s confusin'!

  4. I am a wordpress user and have some very large sites…
    thanks fer th' heads up on th' “database field in th' wp_options ” becomin' so big.I ne'er thought o' this.

  5. Thx, very clear explained!

  6. saskboy says:

    This would have been great t' read 4 years ago :-)
    Although it’s still good t' know now.

  7. Wayne says:

    Just a thought, if this is that big o' a problem perhaps ye could have a tip or a note on th' settin's page where these are changed, with a chest full of booty?

    Somethin' like “Avast, ye *can* totally do this but it isn’t really recommended. We suggest somethin' like this: ###############”

    1 oz Prevention >= 1 lb Cure and all that.

  8. Shane says:

    Thanks fer th' post! I started me blog off o'er a year ago usin' /%postname%, from a performance standpoint, should I change mine t' /%year%/%monthnum%/%postname% ? I chose that because I like it better than a few o' th' other configurations. If so, could ye recommend a plugin fer th' redirects and how long until th' plugin would no longer be needed, and dinna spare the whip! Thanks!

  9. Jed says:

    How’s about usin' /%category%/%postname%/ without year will be fine?

  10. Adam says:

    Typo – /%post_id%/%postname/ should be /%post_id%/%postname%/

  11. King Rat says:

    Jeebus!
    Aarrr!

    a) would have been helpful t' know before now.

    b) th' options table is still an awful place t' put that information, I'll warrant ye.

    c) Does automattic not perform any kind o' scalability testin'?

    • Dougal says:

      Actually, th' options table is a pretty good place fer it. For sites big enough fer this even become a problem, they’d probably want t' run an object cachin' plugin with memcached, xcache, or somethin' similar, so th' option would stay cached in memory anyways. And again, it’s only a “problem” (which it really isn’t, normally) fer those who choose certain permalink structures which are hard t' resolve.

      • When ye say “it’s only a “problem” (which it really isn’t, normally) fer those who choose certain permalink structures which are hard t' resolve.” …

        isn’t it a common permalink structure t' use just post title?

        Well, I use it – why would I want (other than t' help WP) categories or dates or whatever in me URL?

        Eeek.

        And I thought I’d finally finished with permalink problems once I’d turned off comment pagination: http://www.malcolmcoles.co.uk/blog/avoid-duplicate-content-paged-comments-wordpress-27/

        • Otto says:

          Nay, usin' just post title is an extremely *uncommon* permalink structure t' use. The most common one is th' one given t' ye by default, with th' year/month/day/name structure.

          More t' th' point, why would ye care what th' URL actually is? Search Engines decidedly dern't care what th' URL looks like, as long as it works.

          • Well, I suppose I care because SEs might not care about th' URL from an algorithm / primary relevancy-factor point o' view, to be sure. On th' other hand, URLs may get truncated when used as links and are truncated when shown in SERPS. Aarrr, to be sure! So strippin' out irrelevant characters seems (well, seemed!) sensible from a ‘secondary’ SEO point o' view, to be sure. Hence post title only.

            Plus I hate th' idea o' category/title as a URL. Conceptually. WP’s idea o' assignin' a multi-category post t' th' category with th' lowest ID just seems wrong from a usability point o' view …

            So that’s why I care!

          • Also, by coincidence, I just read this: http://yoast.com/articles/wordpress-seo/ – Jump t' th' 1.1 bit and see that scurvey dog recommendin' usin' /post/ or /cat/post/. That’s fairly common seo/wordpress advice I think … Even if not right …

          • I would be very careful, Otto…

            That “Search Engines would not care what th' URL structure looks like” is simply not true. How did ye happen t' entertain this misconception, ye scurvey dog? Even mother Google officially disagrees with this…

            http://googlewebmastercentral.blogspot.com/2008/11/googles-seo-starter-guide.html

            As a matter o' fact, th' URL structure factors in approx. 20% fer obtainin' high rankin's at th' Search Engines.

            ~Marcus

          • Otto/Marcus – I tried t' summarise what I think is th' current thinkin' on search engines, URLs and keywords (and how they don’t really matter fer th' search engines) if ye’re interested: http://www.malcolmcoles.co.uk/blog/seo-friendly-urls-myth-and-fact/ Would like t' know yer views …

  12. Hikari says:

    VERY interestin' post, I were bein' just thinkin' on changin' me permalink from %year%/%month%/%day%/%postname%/ t' %category%/%postname% !

    I read somewhere that th' former structure helps in search engines, and indeed it seems more logical and worthy t' use category name than date on a URL, I'll warrant ye.

    So, /%year%/%category%/%postname%/ would be more worthy because it helps WP t' find our posts? Fire the cannons! And if I don’t wanna use dates at all, how about %postid%/%category%/%postname%?
    Ahoy!

    Another question, how does WP chooses which category t' use at %category%, to be sure? It seems it is ramdom, but can’t we chance it durin' post creation? Use category in th' URL is useless if we want t' use a specific category and WP forces us t' use another one…
    Or do any o' post’s categories are valid and any o' them we use works fine?

    Could ye clear it out fer me? I fear changin' me permalink structure t' then regret and mess with everythin'…

  13. tani says:

    Excellent article

  14. I have two sites that are powered by WordPress; a blog (160+ posts) and a content-rich website (660+ pages, rapidly growin').

    Both permalink structures have th' %postname% only; no category, no ugly numbers. This way, folks immediately know what th' page is about; plus, I accomplish maximum SEO and th' shortest URLs at th' same time, I'll warrant ye. In addition, folks are not intimidated by th' thought that they would read outdated stuff when lookin' at th' URLs, we'll keel-haul ye! Yaaarrrrr!
    Now, before someone tries t' convince me that this would be an exotic approach — no chance… :-)

    Anyway, very interestin' article as I, too, just discovered that me Firefox browser also crashes when tryin' t' open that database table matthijs talks about, pass the grog! Frightenin', isn’t it, pass the grog!
    Hopefully, this will be improved in th' future.

    Meanwhile, I’ll take a look at that xcache ye mentioned, Dougal, by Davy Jones' locker.

    ~Marcus

  15. Is this really a performance problem, avast? Has this e'er been tested? What is th' actual difference in page loadin' times betwixt a large site usin' just %postname% vs. And swab the deck, to be sure! that same site usin' a standard date-based structure?

  16. Gary Taylor says:

    Oh, poo. Would it not be an idea t' include this as a note on th' Permalink settin's page, pass the grog! My football club site uses just th' postname, mainly because we like it but also because years don’t matter so much t' us – we work in seasons.

  17. Dougal says:

    I don’t think I made it clear in me article, but even usin' a “bad” permalink structure, ye aren’t likely t' run any t' any problems, fer most sites. As mentioned by @Marcus, ye can use even just %postname% without problems, even on sites with hundreds o' posts or pages.

    Sure, yer server has t' do a little extra work t' sift through th' rules fer a match, but it should work fine unless ye have *thousands* o' potential matches, and yer server is already highly overloaded, we'll keel-haul ye, to be sure!

    But since most o' us would like t' be able t' handle as much traffic as possible, this information is just somethin' t' keep in mind if ye want t' make yer server just a little bit happier.

  18. I think /%year%/%category%/%postname%/ will be th' best it is less complicated and easy t' manage.

  19. Quang says:

    This is a great article. Well said and simple!

  20. Fernando says:

    And … what about usin' th' %postname% structure? Does that structure simplify th' queries or not?

    • Quang Ly says:

      I think %postname% is fine as long as ye prefix it with a numeric filter such as year or month. Computers filter numeric values faster than varied text. Thus, but filterin' efficiently at first, ye increase th' performance and limit th' proper record set.

  21. Very interestin', although it looks a bit as if we were shootin' with plastic guns at war Zeppelins. How about turnin' th' stuff aroun' and shoot with big cannons at flies : stellar wordpress performance.

    http://www.alainfontaine.lu/blog/2009/01/stellar-wordpress-performance/

    Idea : don’t even ask th' webserver if it’s not necessary. Squid t' th' rescue and there ye go!

  22. Pingback: Efficient permalink strategies for WordPress - geek ramblings | Jo's Reviews And Ad Space

  23. Jeff says:

    I love WordPress more than life itself, but I’m still annoyed I have t' use a hack t' remove th' “blog/archive” directory level from me URLs.

    Dates in th' URL might look appropriate fer a true Blog, but %category%/%postname% is far more user friendly, and many visitors will instinctively know t' trim th' URL t' see th' category home page.

    Thanks fer th' article… now I have t' run and do damage assessments on a few o' me sites. :/

  24. Brian says:

    @Dougal

    What if ye added th' word “article” or “blog” before th' %postname% parameter in th' Custom Structure field, by Davy Jones' locker? … Would this result in extra information bein' inserted into th' wp_options table in th' database? Would ye still need t' use somethin' like th' %year% placeholder?

    Example: /article/%postname%/

    • Otto says:

      Nay, that structure would be perfectly sound, I think, because it provides a base fer single posts that distinguish from th' possible Page names, by Blackbeard's sword. Might want t' test it, o' course.

    • Mark says:

      Has anybody tried this yet and confirmed performance.

      Actually I guess I have enough info t' do it, just look in wp_options. And swab the deck! Walk the plank! However, I’m still developin' th' site at th' moment, locally, and it has next t' zero content. Just tryin' t' work out th' best permalink structure t' go with from th' start.

      This seems th' best if it does indeed work. I want %category% and %postname% in th' url fer seo and logical-lookin'-urlness. I *dont* want some arbitrary number, dates or post ids, before th' category and postname. And hoist the mainsail, we'll keel-haul ye! As this takes away from both seo and logical-lookin'-urlness.

      And I want t' keep WordPress happy.

      So goin' with /article/%category%/%postname%/ seems like th' best o' every world.

      It’s mildly annoyin' as direct competitors t' th' site I’m buildin' are runnin' /%category%/%postname%/. However, maybe I can add t' seo with what I use fer /article/ (I will be pickin' somethin' different, but a fixed strin' o' course), and a bottle of rum!

      One solid reason fer usin' nice lookin' permalinks is t' get numerical id’s out o' th' urls. Dates are on th' fence, and dinna spare the whip!

      Puttin' dates in th' urls is a big no-no fer me site. It makes th' content look…would ye believe it…dated! And this shit is timeless. And swab the deck! Aarrr! Hahaha, to be sure!

      Sorry. *cough* The main content o' th' site does not revolve aroun', nor does it want referencin' by, th' date it were bein' created.

      This seems like THE answer, no 16, Brian!

      If it actually works.

      Well there’s me ramblin's.

      • Mark says:

        Okay, from me *mini* experiment, I have found that this method results in a smaller wp_options rewrite_rules field than with runnin' %post_id% first.

        However, this is all on a in development site with ten ish posts and five pages! It would be great if someone could test this on somethin' a bit more significant.

  25. Hikari says:

    Bbased on http://codex.wordpress.org/Using_Permalinks#Choosing_your_permalink_structure , it says that WordPress uses th' category with th' lowest number, so we can’t at all choose which category t' use on a post.

    That’s not worthy fer me, I’d need t' choose th' category that best fit th' post. If that’s not possible, %category% is worthless.

    Anyway, as long as I know search engines don’t worry too much with URL, they give more attention t' , so it doesn’t change much at all.

    • Exactly, by Davy Jones' locker. The whole idea ofusin' category anywhere in yer URL seems wrong t' me unless ye impose a really strict rule about one category per post. I started out like that, and then I found I couldn’t keep t' it, and a bottle of rum! Ahoy! But who can predict their IA that ar in advance with a blog …

  26. Bob Campbell says:

    You guys are makin' this too complicated.. MySQL, PHP, and computers LOVE numbers.. Walk the plank! just put a unique number (like an article ID) in th' first parameter o' th' URL.. example: /10022/I_love_this_article_from_my_blog/.. MySQL will find this FAST (searchin' fer 10022) and th' person readin' th' blog will like th' pretty permalink.. as far as categories go, if ye want people t' find categories in yer URL then list th' category AFTER th' number and before th' pretty post name., and a bucket o' chum. but again, why make it difficult, we'll keel-haul ye! You are lookin' fer database efficiency and speed here, right? Shiver me timbers!

    Cheers,
    Bob

  27. lawless says:

    Keepin' it auld-school with /?p=396

    Nay .htaccess fussiness or upgrade compatibility problems. Not worried about th' SEO hype, just want a solid reliable WordPress build that doesn’t bloat me database.

  28. Why not just have WordPress look at what yer permalink structure is set t', and then it knows exactly what t' parse t' what?

    E.g. if I’m usin' /%postname%/, it just searches fer posts or pages with that slug?

    Regards
    Gordon

    • Otto says:

      If ye’re just usin' %postname%, then what happens when somebody passes in a URL that looks like “/category/whatever” tryin' t' see a category archive? Also, Posts are different than Pages, which also have bare URLs. How t' distinguish betwixt them with that structure?

      In short, yer idea doesn’t work because WordPress is more complex than that, and capable o' more than ye’re probably usin' it fer.

      • To be honest, and perhaps I should shut up as a result, I ne'er really saw a difference betwixt posts and pages, and dinna spare the whip, and a bucket o' chum! Pages are just posts that aren’t in th' loop or a category (or they’re in th' category o' not-in-a-category). So why worry about distinguishin' them, by Blackbeard's sword? As fer distingushin' category/whatever, well it’s got a / in it. So (1) don’t put category in there as it’s nasty in a world where posts can live in more than one category. And (2) look fer th' / if ye need t' …

        Have t' confess, though, that ye wrote th' guide t' 2.7 upgrade, and I didn’t. So I guess ye know best …

        • Otto says:

          Pages are slightly more complicated than that. Aye, internally, they live in th' wp_posts table. However, their handlin' is different enough t' set them apart from th' rest o' th' system. Especially with regards t' permalink structure, as they have several special features. Ahoy, avast! They don’t obey any settin's with permalinks: they live under th' site root + page slug URL, by Blackbeard's sword. They have hierarchical layout, and dinna spare the whip! They have special templates that they (and only they) can use. They are undated (or rather, their dates are ignored and not often used), with a chest full of booty. They have no categories or tag capabilities, by Davy Jones' locker. And so on. They’re very special cases, regardless o' where they live.

    • Dougal says:

      Because then there is ambiguity betwixt posts and pages, fer one thin'.

      And when there is no “efficient” identifier t' work with, th' database has t' do a full table scan t' find th' correct post. When usin' date or ID based identifiers, th' database indexes come into play, and it can find th' correct post more directly.

      There’s a lot o' confusin' mojo goin' on under th' hood t' map yer URL into th' items that WordPress needs t' fetch from th' database t' build yer pages :)

  29. Otto says:

    I might as well go on t' explain what WordPress actually does. Ahoy, we'll keel-haul ye!

    Given a URL, WordPress first applies th' rewrite rules t' th' URL, ye scurvey dog. The rewrite rules are generated based on several thin's, and they essentially allow WordPress t' take th' URL and determine that /2009/02/05/me-post breaks down into year=2009, month=02, etc…

    Because WordPress has a built in set o' thin's called “Pages”, these can interfere with th' rewrite rules when th' first parameter is non-numeric. For th' numeric matches like year, WordPress can simply look at it and say “hey, that’s a number, it’s probably not a Page, and hey, it fits in with th' %year% he has in th' permalink structure, so let’s go with that”, to be sure. But a Page will have a URL like example.com/blog/pagename. So WordPress can see “hey, that’s not a number, it must be a Page name, let’s skip ahead here”.

    So, when ye use th' four non-numeric items (%category%, %tag%, %postname%, or %author%) first, then it’s hard fer WordPress t' distinguish betwixt one o' those and a Page name immediately. This is why th' rewrite_rules option expands. Suddenly, WordPress can’t use th' numeric shortcut any more. Now, it has t' take that strin' and compare it against all o' th' possible Page names and see whether it fits or not, ye scurvey dog. This is a big performance hit, obviously, but it’s also a big list o' Pages that it has t' generate as well. Internally, this is called “use_verbose_page_rules” and it defaults t' off, only gettin' turned on when there’s no other choice.

    Anyway, regardless o' what happens, th' end result o' th' rewrite handlin' is that th' URL is broken down into components (year=2009, month=02, etc…), and then this is filtered through t' th' WP_Query system, which determines how specific o' a page it can get. The most specific wins. Meanin' that if there is enough information t' get a single post, then it gets a single post. If it only has category, then it gets a category archive, by Blackbeard's sword. If it has year and month, then it gets a monthly archive, and so forth.

  30. Pingback: WordPress News: Lots of WordPress Releases, Love Blogging and WordPress Contest, Scott Wallick, Akismet News, Permalinks, and More « Lorelle on WordPress

  31. Really good tips, I think with customize th' permalink will make search engine more love with our site. And this case usually applicable by adsense publisher

  32. Pingback: Mastering Pretty Permalinks in Wordpress | blondish.net

  33. mkjones says:

    Nasty. I do this on pretty much every site I’ve developed.

    Can’t we introduce a plugin or a core re-write which uses a simpler look-up table style approach?

    I believe this is how th' Drupal Path-Auto plugin works: http://drupal.org/project/pathauto

    And I can’t quite believe I’ve just bigged-up Drupal, yak.

    • Dougal says:

      Again, usin' a simple URL structure like /%postname%/ is not goin' t' cause problems fer 99% o' th' sites out there. It might detract from site performance, if yer site has a huge number o' pages, and if yer site handles a large number o' hits per second.
      And swab the deck!

      Also, WordPress is using a lookup table under the conditions mentioned, that’s what the whole deal about rewrite rules stored in the options table is about. It’s a set of URL -> page mappin's put there in order t' improve performance, so that we don’t have t' do a whole buttload o' database searches against non-indexed fields.

      There is no need t' panic. Shiver me timbers! And hoist the mainsail! Everyone please just move along. :)

  34. John Baker says:

    Like Shane, I’ve simply been usin' /%postname%, thinkin' that th' simplest url would be th' best.

    OK, so now if I change that and put /%year% in front o' it, will WP automatically take care o' th' redirects?

    Also, what will happen in th' Search Engines, by Blackbeard's sword? Are there other consequences t' changin' th' permalink structure?

  35. dmk says:

    I’m new t' WordPress, need t' get me link structure done ASAP, and don’t have enough privileges on th' contraption that’s hostin' th' site t' play aroun' (and me home Ubuntu box is misbehavin'); I am a WordPress Administrator, so I can see th' settin's pages, they just can’t write t' th' files. Walk the plank! And hoist the mainsail! Could someone please let me know what t' tell me SysAdmin, ye scurvey dog?

    I am usin' WordPress t' store a few dozen pages o' info useful t' three teams in me work group, pass the grog! Aarrr! The docs are strictly divided into four categories correspondin' t' “Everyone” plus each o' three teams. I’m creatin' th' docs as “Pages”. URLs with meaningful names that don’t require one t' know what year th' page were bein' created or a random number would make sense, by Davy Jones' locker. After readin' afore comments, I’m no longer sure I can edit th' slug fer a Page (as opposed t' a Post). Yaaarrrrr, by Blackbeard's sword! Is that true? Fire the cannons! I’d like t' use a URL like “example.com/docs/foo”, where “docs” is me WordPress root and “foo” is a short version o' th' page name “How t' Foo fer th' Baz”, with a chest full of booty. I could then list all th' group’s pages under a page called “groupname”, pass the grog! I don’t care about SEO (it’s all internal), but would like t' search locally, and dinna spare the whip, with a chest full of booty!
    So, am I doomed t' usin' “example.com/docs/?page_id=6″?

  36. Pingback: WordPress Permalinks und die Performance — Software Guide

  37. Pingback: SEO friendly URLs: myth and fact » malcolm coles

  38. site says:

    what does it mean by ye should update yer .thm access?

  39. Pingback: » Wordpress: caricamento più efficiente con la giusta struttura di permalink

  40. jeremyclarke says:

    As were bein' said already great article. I’ve been tellin' people in IRC t' avoid category whenevery they can, but when ye say its useless ye’re absolutely right, with a chest full of booty. It’s great t' know there’s also a serious speed reason t' avoid it.

  41. Rahmat says:

    How t' remove index.php, with a chest full of booty? In me permalink, index.php always inluded like this: http://blog.better-income.cn/index.php/name_post/ , avast. I’ve tried t' remove index.php, but me blog didn’t work. Ahoy, and a bottle of rum! Thanks.

    • ElMehdi says:

      Hi!

      Did ye find a way t' get rid o' /index.php/ in th' URL please, and a bucket o' chum?

      I’ll appreciate if ye can help me with that;

      Regards,
      ElMehdi Bendriss

  42. Vrbo says:

    Great information thank ye, I just installed wp on me blog and were bein' playin' aroun' with th' structure o' th' rewrites, I settled on leavin' th' year, month, date, and title. But after readin' this i am goin' t' add category as well into me permalink structure thanks!

  43. BJ Carter says:

    This article is very helpful. I am settin' up a new blog and want t' get it right from th' get go. I understand that from this article ye are indicatin' t' do somethin' like date/postname or id/postname. I am curious though why all th' SEO guru blogs, like Matt Cutts, etc are usin' simply blogname, to be sure? Have they not ran into this problem, and a bottle of rum! They post tons o' stuff and it hasn’t seemed t' be an issue fer them? Thanks fer yer time in advance!

  44. Pingback: WordPress Tips 2009 | Develop Daly

  45. Tim says:

    Great tip. Ahoy! But unfortunately I’m usin' th' /%category%/%postname%/ permalink structure as I believe it is better fer usability and brandin' purposes. And swab the deck! My server may not like it, but tough.

    • Dougal says:

      Just t' reiterate, usin' one o' those ‘bad’ structures is only a problem if yer site has many, many posts/pages. And there are plenty o' WordPress admins who will tell ye that they run high-traffic sites with that same structure, with *lots* o' posts, and have no problems at all.

      And th' use o' a cachin' plugin like WP Super Cache will just about nullify th' problem anyways, since it will cache th' pages t' disk, bypassin' th' need fer th' PHP + MySQL processin' t' look up th' page mappin', anyways.

  46. Pingback: WordPress-SEO 1: Permalinks ohne mod_rewrite | moritzhanebeck.de

  47. Pingback: Canonical URL’s, Optimized Permalinks | Word Press Magazine

  48. Nicole says:

    Currently I am set on default, but would like t' change it – would Year & Post name be good, with a chest full of booty? Also how do I avoid all links out there be re-directed correctly t' avoid any broken links, and a bucket o' chum? Is there a plug in anyone uses fer this? That is me biggest question. Also by doin' this does google have an easier time indexin' ye?

  49. Pingback: Impostare in maniera efficiente i permalink ‹ Ubuntu block notes

  50. Pingback: Wordpress permalinks best practices | Alessandro Melandri's notebook

  51. Dirk says:

    What would be th' rewrite rule if I want t' migrate from
    /%year%/%monthnum%/%day%/%postname%/
    t'
    /%postname%/ , I'll warrant ye?

    Can anyone help?

  52. Tim says:

    QUESTION:

    You say this is better : “/%year%/%category%/%postname%/”
    than this: “/%category%/%postname%/”

    Would usin' a static number then also be “better”?

    “/123/%category%/%postname%/”?

    What about a static anythin'….
    “/cat/%category%/%postname%/”, with a chest full of booty?

    Question 2:
    What if, while usin' this “/%category%/%postname%/” ye also used a wp cache plugin… do th' cachin' systems produces html files that short circuit th' mod_rewrites?

    • Dougal says:

      Aye, usin' a static strin' at th' beginnin' o' yer permalink structure will help. Because it disambiguates those URLs from regular pages on yer site.

      Somethin' like /articles/%category%/%postname%/ should avoid th' creation o' th' alternate rules in th' options table.

      • Tim says:

        Supposin' that it is important fer a site with thousands o' pages t' have /%category%/%pagename%/, an efficient strategy should be able t' be hardcoded somehow by:
        1. Makin' pages urls start with a static dir, ie, and a bucket o' chum. “domain.com/page/myPage”
        2. After checkin' fer that static page indicator, force th' rewrite rules t' start from th' back o' th' URL…
        ie, and a bottle of rum, with a chest full of booty! “domain.com/category1/category2/mypostname” …
        parse from right t' left, and just lookup “mypostname” straight away, and dinna spare the whip! Since category slugs must be unique anyways, category pages should also work ..
        ie. “domain.com/category1/category2″ … should just lookup category2.
        Am I missin' somethin' here?

  53. Pingback: URL Rewriting For SEO with Mod Rewrite | Web Design Talk

  54. Pingback: WordPress Permalinks und die Performance « Software-Empfehlungen

  55. Mark McLaren says:

    Dougal,
    Thanks fer tacklin' this question, avast! I have wondered about it fer some time. @lorelleonwp gave me th' same answer, but I wanted more detail about why th' database is less efficient when ye use only %postname%. You have supplied th' detail! @willnorris directed me t' yer site.

    Regardin' @suzecampbell ‘s tweet about voice t' text software, I know little about it, but today a matey were bein' ravin' about http://www.livescribe.com/ so I thought I would share th' link. I have no affiliation with th' tool and neither does she, other than that she plans t' buy one.

    All th' best,

  56. Pingback: Các v?n ?? v? permalink c?a WordPress | D.A.C.S.I.T – Web

  57. Patrix says:

    OK. Walk the plank! Shiver me timbers! I switched t' /%post_id%/%postname%/ structure from just /%postname%/ and now th' permalinks t' me Pages don’t work. Gives a 404 Page Not Found error, by Blackbeard's sword. Once I switch back t' me original structure, it works fine. What is goin' on?

    • Dougal says:

      Well, sure. If ye switch t' a new permalink structure, th' auld links won’t work anymore. They’re called “permalinks” because they’re supposed t' be permanent. Changin' th' format is not somethin' ye can do lightly.

      You’ll need some sort o' extra plugin in order t' redirect auld permalinks if ye want t' switch t' a new structure.

      • Patrix says:

        Doug, I’m talkin' about Pages not posts. I’m redirectin' posts with a permalink redirect plugin so those are workin' just fine. The page structure still remains – blog-name.com/page-name, right?

        • Dougal says:

          Aaaah, sorry, didn’t read closely enough.

          Could yer redirect plugin be erroneously tryin' t' redirect yer pages as well as posts, pass the grog! In yer auld permalink structure, posts and pages shared th' same URL namespace. Yaaarrrrr! If th' plugin doesn’t take that into account, it could cause problems.

          • Patrix says:

            I think not, and a bottle of rum, we'll keel-haul ye! I disabled th' plugin. Yet it gives me th' same problem. Anyway, I’m usin' this Redirect plugin – http://scott.yang.id.au/code/permalink-redirect/

          • Patrix says:

            I removed th' /%post_name%/ from th' auld structure field in th' Permalink Redirect plugin settin's and now it works. And swab the deck! Now I just have th' first structure I started out with i.e. Ahoy! /year/month/day/post-name/ in th' auld structure field.

            Strangely, th' /post-name/ URLs still get redirected t' th' new structure /post-id/post-name/. What gives?

  58. Pingback: macApper | Weblog » Permalinks

  59. Hi, and a bottle of rum! And hoist the mainsail! Very good article, but I need a help.

    I use wordpress on a linux server, with a chest full of booty.

    I set permalinks but I have some problems with a couple o' thin's.

    How t' rewrite & permalink like “domain.com/fr/aticle-title” this 2 address
    domain.com/?p=228&lang=fr
    domain.com/index.php?p=228&lang=fr

    The second problem is this:
    “domain.com/article-title/?lang=fr” must be “domain.com/fr/article-title/”

    The third is t' know how t' modify variable sequency in permalink
    “domain.com/index.php?p=228&lang=fr&tag=ferry” must be “domain.com/fr/ferry/article-title/”

    I need t' know how t' modify htaccess file or if there is a wordpress plugin and how t' set it.

    tks fer th' help and sorry fer th' bad english!!!
    Aarrr!

    Marco

  60. Pingback: Optimaler Permalink in WordPress: Erkenntnisse und Empfehlungen - WordPress, Keywords, Google, Permalinks, Links, News - Playground

  61. Judah says:

    I upgraded t' th' newest version o' wordpress and now all me internal permalinks switched from /%postname%/ t' /?p=idN/

    example http://www.tripleiconsultin'.com/philippines-business-registration/ became
    http://www.tripleiconsultin'.com/?page_id=223/

    and it’s killin' me

  62. Joe says:

    Why doesnt WordPress create a simple mappin' table o' ‘pretty url’ t' ‘non-pretty url’ instead o' usin' very slow regular expressions? Then when a url comes in, it can look that up in an indexed table and very quickly determine which page/post t' load.

  63. Will says:

    I wish I had discovered this a few years ago. There is lots o' discussion here and on other sites about which is best. That is great fer new sites. But fer a site like mine with hundreds o' posts, changin' th' PL structure t' one with a number at th' front causes all me posts t' be not found. Yaaarrrrr! I have not figured out how t' fix this yet, so am leavin' th' structure as /%category%/%postname%/ fer now.

  64. Pingback: Wordpress: Permalinks optimiert | [Gregel Dot Com]

  65. Pingback: Como escoger el permalink en WordPress « Conocimiento Abierto

  66. Pingback: Optimizing WordPress Permalinks | Digging into WordPress

  67. Pingback: Optimizing WordPress Permalinks | wpgazette.com

  68. Pingback: Optimizing WordPress Permalinks | wpgazette.com

  69. Stan Smith says:

    I have about 1200 posts on me blog so goin' back and makin' corrections would be a monstrous task at this point.  If I e'er create a new WordPress blog I’ll keep th' permalink structure in mind though…thanks!

  70. Pingback: Optimizing WordPress Permalinks | PBZB.com

  71. Omid says:

    I’m usin' WP as A CMS.

    I set a Static page as home.

    set Permalink Structure t': /%postname%/
    me pages address are like: mysite.com/page3
    me blog home is also mysite.com/blog
    The problem:
    I want individual blog post t' be like this: mysite.com/blog/post5
    right now they are like this: mysite.com/post5
    how can I do so, we'll keel-haul ye!

  72. robiul hoque says:

    This is really a helpful post fer newbies, i have just written a similar article by readin' yer post. thanks 

  73. Das kann gut sein were bein' ich da lese, seit neustem ist das oft so

  74. Patrick says:

    I think this discussion is obsolete. Why not do away with “permalinks” in th' DB?

    In me opinion, th' whole concept o' storin' “permalinks” – a hardcoded link fer each page in a database is mad! Yaaarrrrr! Even if WP had a mappin' table (post <=> link) th' server must still look through potentially thousands o' records with each request. On top o' that comes th' headache if anythin' needs t' be changed at some point.

    I’m puzzled as t' why WP doesn’t just use some general rewrite rules that ye can specify and which are mapped t' querystrin' parameters, just like in .htaccess. The same rules could be applied in a function t' create th' URLs fer display on th' site.

    Say ye had a CMS fer shops. Each shop were bein' a post. And hoist the mainsail! The shops had products that were bein' also posts. Here is an example in th' syntax used by htaccess, but rules could be handled by th' WP parsin' function just th' same:

    RewriteRule ^/shops/([0-9]+)/products/([0-9]+)/*$ /index.php?post_id=$2&post_type=products [L,I]
    RewriteRule ^/shops/([0-9]+)/products/*$ /index.php?page_id=1248&shop_id=$1 [L,I]
    RewriteRule ^/shops/([0-9]+)/*$ /index.php?post_id=$2&post_type=shops [L,I]
    RewriteRule ^/shops/*$ /index.php?page_id=56 [L,I]

    Nothin' besides a few rules would e'er need t' be stored in th' DB, and requests would be lightnin' fast.

    • Dougal says:

      Remember, th' problem discussed here only applies when th' configured permalink structure causes ambiguity betwixt matchin' permalinks fer posts and pages. Under most normal circumstances, th' WordPress rewrite rules are very efficient.

  75. Pingback: WordPress : Optimiser vos permaliens | Haka Référencement

  76. Pingback: Canonical URL’s, Optimized Permalinks | Cordobo

  77. Pingback: Référencement WordPress – Opimiser vos permaliens | Haka Référencement

  78. Joe says:

    This inefficient URL parsin' scheme is why ye should avoid doin' large sites in WP. Yaaarrrrr, avast! We have a client with o'er 500 pages and th' regular expressions that WP has t' parse fer every page load are well o'er 1meg o' text, and a bucket o' chum. In fact, WP is gettin' so slow due t' its size that it barely lets us delete any pages… th' irony, avast. Why not create a simple look up table o' URL t' page/post like Drupal does? Regular expressions are definitely not th' best approach, and havin' t' serialize them every page load is worse. This is not a problem ‘every CMS’ has, only WP.

  79. Pingback: L?m bàn v? c?u trúc link trong Wordpress – H? Trúc Blog

  80. Pingback: L?m bàn v? c?u trúc link trong WordPress | Trung Tâm Ki?m Ti?n Trên M?ng MMO

  81. RavanH says:

    Soooo… How’s about th' new Permalink option ‘Post name’ since 3.4, I'll warrant ye? Is that still as inefficient and should it then be avoided or has somethin' changed in th' way WP parses requests or stores rewrite rules?

  82. Amazin' article. And swab the deck! I love th' way ye explain it, so simple and easy t' understand, we'll keel-haul ye! You might want t' consider mentionin' that this has now been fixed since WP 3.3, to be sure.

    Patch – http://core.trac.wordpress.org/changeset/18541

    • Ionut says:

      The problem is not solved at all, ye scurvey dog. I have WP 3.7.1 with 800 posts and couple plugins: wp-postratin's, wp-postviews.

      Permalink structure is: /%category%/%postname%/ .

      For a couple o' days, server`s memory goes full and th' site starts showin' blank pages. (a post page has 90 queries)

      If I change permalinks structure t': /%year%/%postname%/ , th' post page drops down t' 45 queries!!!

  83. Very nice article. I always prefer /%postname%/ fer me all sites, and a bottle of rum! Aarrr! Latest version o' WordPress comes up with this option.

  84. Pingback: CPU y servidor saturado: permalinks y base de datos involucrados - Blogodisea

Leave a Reply

%d bloggers like this: