Most blog powered by WordPress use ‘pretty’ links structure. This allows you to have hierarchical structure of the URL elements and that is much easier to read, and can even contribute to SEO results. And to achieve this WP adds rewrite code into htaccess.
Original WordpRess code is this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And, this is usually left as it is, and it works just fine. But, this actually can be better and not only that, changing this piece of code can speed up your blog by avoiding some of the unneeded file and folder checks that rewrite module will perform based on the original WordPress code.
JP Morgan has suggested modified rewrite code to be used in the htaccess that will perform much better:
# 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|jpeg|jpg|png|ico|css|js)$ [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
On line 11 you see a number of extensions that will be excluded from rewrite checking. It’s not good to have too many extensions here because they cam have negative impact. Images, CSS and JS are enough to have here. This new code also removes IfModule check. If you already have mod_rewrite this check is useless, if you don’t have mod_rewrite than you need to turn of the permalinks in the WordPress. You can safely remove all lines starting with #, they are only comments.
Actually speedup gain depends on many factors: size of the website, speed of the server and things like that. If you have small blog, speedup will be small, but in many cases you will be able to notice it. JP Morgan claims that htaccess processing with changed code is cut in half and that has great positive effect on the website performance. I tested the code on two websites for now, and it works good, and some speed gains can be measured.
Source at WebmasterWorld.com: http://www.webmasterworld.com/apache/4053973.htm
Tags: checks, elements, hierarchical structure, htaccess, impact images, jp morgan, permalinks, pretty links, rewrite, rewriterule, sourcecode