This page uses Javascript. Your browser either doesn't support Javascript or you have it turned off. To see this page as it is meant to appear please use a Javascript enabled browser. Need help?

Blog

WordPress Times Out With Too Many Pages?

 Categories: WordPress Tricks

wordpress permalinks caused me to pull out my hair!This one had me pulling my hair out for a few days. 

I was developing a client site in WordPress.  This site had 500 products and I chose to use Pages (instead of Posts) for the products, mostly because it allowed for a better URL structure, especially because there were product categories and sub-categories.  The URLs would look nice — www.site.com/category/sub-category/product-name/

Spoiler!
No time to read the entire post?  Just update your permalinks to /%year%/%postname%/ and that will fix the issue.  If your site is running too slowly to edit the permalinks, edit the database directly.  I use phpMyAdmin.  Search the wp_options table field name for %LIKE% = permalink and edit the value to /%year%/%postname%/

All was going well in development until we hit around 400 pages.  Then the site started running reaaaaaallllly slowly, and even timing out with a PHP fatal error like this:

Maximum execution time of 30 seconds exceeded in /wp-includes/rewrite.php on line 835

WTF!  Could this be a plugin issue?  Or something wrong in our custom coded theme?  I didn’t think so… but what else could it be?  Surely WordPress can handle a website with thousands of pages, right?

My first thought was “there must be something wrong with the server.”  We did have a separate sub-domain for the site dev.site.com so that was a variable worth looking into.  Also, I had just started using a new VPS from Host Gator running Fast CGI (I usually run PHP as an Apache module) so that could also be the cause.  Fun, I get to figure this out! [sarcasm]

No luck with tweaking the server settings, although Host Gator support does get an A for effort.  And I even updated the php.ini memory_limit from 64M to 128M thinking that this could be the root of the issue.  Nuts.

Turns out that good ol’ permalinks is the cause of this problem.  For those that don’t know, permalinks allow you to customize the URL for your WordPress site.  Very useful for search engine optimization (SEO).  In classic obscure fashion that us web developers have grown used to (thanks to IE6 debugging and for the truly old skool, Netscape Navigator 4 hacking), the solution is to add something other than /%postname%/ to the start of your site’s permalinks.

I’ve found that both of the following work equally well:

  • /%year%/%postname%/
  • /blog/%year%/%monthnum%/%postname%/

Not only will this bring your many-paged-Wordpress-website back to life, it will not affect your Pages URLs.  In this case, the permalink structure only applies to your Posts.  Yay!!!

Hopefully this breakdown will save a few hairs on your head.  I wish I had found out about it earlier 🙂  Many thanks to the following which helped me out:

Comments
  1. Jake Rocheleau on 8/10/2011 at 10:43
    Reply

    Thanks so much for this it was driving me nuts! I would have never figured this out without your post, really informative.

    • admin on 8/10/2011 at 10:43
      Reply

      Glad that you found the post useful Jake. I’ve been using the /%year%/%postname%/ on all my WordPress sites since figuring this out. It’s good practice in case the site page count grows over time. I also think including the year in the URL will help for the SERPs more than it hurts, especially in a few years from now, it will show that this post has stood the test of time (assuming it’s not outdated!).

  2. Patrick on 8/10/2011 at 10:43
    Reply

    WOW! This worked! I’m wondering to myself “Can it really be this easy?

    Sure enough!

    Thanks a MILLION!

    • admin on 8/10/2011 at 10:43
      Reply

      Cheers Patrick!!

  3. razen on 8/10/2011 at 10:43
    Reply

    I think it is working for all but
    I could not change the permalinks, when i go to Setting>Permalinks it shows error
    Fatal error: Allowed memory size of 44040192 bytes exhausted (tried to allocate 113 bytes) in /home/hletang/public_html/wp-includes/rewrite.php on line 1544

    how to resolve

    • admin on 8/10/2011 at 10:43
      Reply

      Razen, try editing your database directly using phpMyAdmin. In the “wp_options” table, edit the field “permalink_structure” to be /%year%/%postname%/

  4. razen on 8/10/2011 at 10:43
    Reply

    Thanks Admin, I got the field 🙂

Add Comment
Add Comment