jump to navigation

WordPress Performance January 12, 2010

Posted by learnseofree in WordPress SEO.
trackback

Were you aware that WordPress modifies your root .htaccess file when you install it?  The code that is placed in your .htaccess for WordPress is actually very inefficient.  Jim Morgan at Webmaster World posted a great solution for optimizing the needed .htaccess code to improve WordPress performance.

The default .htaccess code installed with WordPress is as follows:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Jim suggests changing this to

# BEGIN WordPress
RewriteEngine on
#
# Unless you have set a different RewriteBase preceding this point,
# you may delete or comment-out the following RewriteBase directive
RewriteBase /
#
# if this request is for “/” or has already been rewritten to WP
RewriteCond $1 ^(index\.php)?$ [OR]
# or if request is for image, css, or js file
RewriteCond $1 \.(gif|jpg|css|js|ico)$ [NC,OR]
# or if URL resolves to existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# or if URL resolves to existing directory
RewriteCond %{REQUEST_FILENAME} -d
# then skip the rewrite to WP
RewriteRule ^(.*)$ – [S=1]
# else rewrite the request to WP
RewriteRule . /index.php [L]
#
# END wordpress

It’s the following statements in the default WordPress .htaccess code that can be very inefficient:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Evidently depending on how your servers are configured and the amount of traffic, these calls often require a disk read for each… That’s 2 reads per pass times 2 passes for a total of 4 disk reads using the default .htaccess code from WordPress.  Jim’s optimizations eliminate the 2 reads from the 2nd pass when a WordPress page is requested, and it eliminates all 4 disk reads when image, JavaScript, and CSS files are requested.

This “tweek” to the .htaccess file cut my page load times in half.

Advertisement

Comments»

No comments yet — be the first.

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 )

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

Follow

Get every new post delivered to your Inbox.