WordPress pages, don’t trash, delete!

There is one downside to keeping your pages in the trash when using WordPress, and it’s something i only came to realise when i was looking over the rewrite rules array recently. After reading a series of posts to the hackers mailing list regarding permalinks i was curious to actually take another look at the array of rules, upon doing so i came to notice something, that i had never considered before.

Pages specifically will each at a minimum take up 5 rules in the array, usually 11, and more depending on whether you have sub-pages and attachments with any of those pages (the top level one, and the sub-pages). With a site driven in pages your rewrite array is likely to be huge simply as a consequence of using alot of pages.

UPDATE: Above is only true if running verbose rules (see further down)

The issue..

Pages in the trash will still remain in the rewrite array. Each page can take up quite alot of rules, if you leave old pages in the trash you’re actually losing out on a potential boost to load times.

Here’s what a very basic rewrite array could look like, look closely at how many rules the pages alone take up compared to say, … category rules, comment rules, or feed rules.

UPDATE: The below rules, are actually what’s known as verbose rules if i’m not mistaken, which was a result of me using /%post_name%/ for my permalink structure.

There are clear disadvantages to using certain permalink structures, and without me trying to babble my way through, i’d rather refer you here to Otto’s post regarding permalinks and the rewrite rules, which certainly has taken my understanding that little bit futher, thanks Otto.

$example = array
    [robots\.txt$] => index.php?robots=1
    [.*wp-atom.php$] => index.php?feed=atom
    [.*wp-rdf.php$] => index.php?feed=rdf
    [.*wp-rss.php$] => index.php?feed=rss
    [.*wp-rss2.php$] => index.php?feed=rss2
    [.*wp-feed.php$] => index.php?feed=feed
    [.*wp-commentsrss2.php$] => index.php?feed=rss2&withcomments=1
    [top-page-4/attachment/([^/]+)/?$] => index.php?attachment=$matches[1]
    [top-page-4/attachment/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
    [top-page-4/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [top-page-4/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [top-page-4/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
    [(top-page-4)/trackback/?$] => index.php?pagename=$matches[1]&tb=1
    [(top-page-4)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?pagename=$matches[1]&feed=$matches[2]
    [(top-page-4)/(feed|rdf|rss|rss2|atom)/?$] => index.php?pagename=$matches[1]&feed=$matches[2]
    [(top-page-4)/page/?([0-9]{1,})/?$] => index.php?pagename=$matches[1]&paged=$matches[2]
    [(top-page-4)/comment-page-([0-9]{1,})/?$] => index.php?pagename=$matches[1]&cpage=$matches[2]
    [(top-page-4)(/[0-9]+)?/?$] => index.php?pagename=$matches[1]&page=$matches[2]
    [top-page-3/attachment/([^/]+)/?$] => index.php?attachment=$matches[1]
    [top-page-3/attachment/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
    [top-page-3/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [top-page-3/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
    [top-page-3/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
 --- *trimmed

Now say i had decided i didn’t want to use pages on my site, so i moved them to the trash. The rewrite array above would hold onto over 50 rules for pages i was no longer using.

So is there ever a reason to flush out the trash, hell yes!… especially when it comes to pages.

There are good uses for the trash of course, i’m just pointing something out that may not otherwise be obvious for some users.

UDPATE: Having read Otto’s blog post about permalink structures i see there are clear disadvantages in particular custom structures, and that can be evidenced from looking at the sheer size of the rewrite array when using verbose rules, like those that were posted originally(above). I’ve trimmed the list as my original point doesn’t really matter too much now.. (the snippet still illustrates the issue with pages in verbose rules).

This does not negate the fact trashed pages are left in the rewrite array, if you’re using a permalink structure that uses verbose rules then you’ll want to keep the array as trim as possible, so ideally pages should never be trashed(delete), just to help clear them out the rewrite array.

I do see that this would be problematic to avoid, how could you deal with the rewrite rules, you’d probably need to regenerate them every time an item was trashed and/or restored (what a nightmare), at least once an item is intended to be deleted, as in gone forever, it makes sense to regenerate the rewrite array, you’re then essentially cleaning house and getting rid of old rules that no longer need apply.

It does make sense how the system currently works, and i take back what i said before. That will teach me for jumping the gun and assuming i know more then i do….hehe…

5 thoughts on “WordPress pages, don’t trash, delete!”

  1. This is a fascinating study of the WordPress pages. I was wondering how you manged to pull out the re-write rules to see them?

  2. I have a lot of question about rewrite rules, i hope you can answer them:
    How can I see how many rewrite rules are in my blog ?
    The are wrote in a file on in a table of db ?
    How i can decide if there are a normal number or too many rewrite rules ?
    There is a way to clean or delete it ?
    If i change my permalink structure the extra rewrite rules will be deleted ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s