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 WordPressAnd, 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 wordpressOn 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







Comment Link
Hi MillaN,
I’m currently using a mix between a Drupal .htaccess and your modified WP .htaccess file.
Just FYI but here’s my .htaccess file (the piece before your posted code that is):
# Make WordPress handle any 404 errors.
ErrorDocument 404 /index.php
# Force simple error message for requests for non-existent favicon.ico.
# There is no end quote below, for compatibility with Apache 1.3.
ErrorDocument 404 "The requested file favicon.ico was not found.
FileETag None
# PHP 4, Apache 1.
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
# PHP 4, Apache 2.
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
# PHP 5, Apache 1 and 2.
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
SetOutputFilter DEFLATE
# Requires mod_expires to be enabled.
# Enable expirations.
ExpiresActive On
# Cache all files for 2 weeks after access (A).
ExpiresDefault A1209600
ExpiresByType image/jpg "access plus 1 months"
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
ExpiresByType text/css "access plus 1 months"
ExpiresByType text/javascript "access plus 1 months"
ExpiresByType application/javascript "access plus 1 months"
ExpiresByType application/x-shockwave-flash "access plus 1 months"
# Do not allow PHP scripts to be cached unless they explicitly send cache
# headers themselves. Otherwise all scripts would have to overwrite the
# headers set by mod_expires if they want another caching behavior. This may
# fail if an error occurs early in the bootstrap process, and it may cause
# problems if a non-Drupal PHP file is installed in a subdirectory.
ExpiresActive Off