While reading Michael Gray’s post on WordPress’ scalability, I followed this link to a webmasterworld.com forum on WordPress’ default .htaccess code. jdMorgan replied to thread with a whole new set of code to replace the .htaccess file that WordPress installs to optimize the URLs in a blog. jdMorgan had rewritten the .htaccess code in order to,
…fix several performance-affecting problems. Notably, the unnecessary and potentially-problematic <IfModule> container is completely removed, and code is added and re-structured to both prevent completely-unnecessary file- and directory- exists checks and to reduce the number of necessary -exists checks to one-half the original count (due to the way mod_rewrite behaves recursively in .htaccess context).
Without further ado, here is jdMorgan’s new code to completely replace what WordPress automatically installs:
# 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|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
Our Unofficial Results
I’ve been a bit concerned with how quickly a couple of our WordPress installs have been loading, so I was anxious to give this a try. I did some testing on two sites as they are now. Most of the pages were taking about three seconds to load (yes, I took the cache out of the equation). I installed the new code and tried again (cache still turned off) and the pages were installing in somewhere around two seconds. About a 50% increase in load speeds. This is all, of course, very unscientific, but that much of a change was enough for me to write this post.
Of course, your milage may vary! It might even crash your website for all I know?I’m certainly not guaranteeing jdMorgan’s code. All I know is that it seems to have sped up a couple of our WordPress-powered blogs.
How to Change the .htaccess File
- Log in to your WordPress install via your FTP client.
- Navigate to the root of the install. This usually means inside the “public” folder.
- The .htaccess file is an “invisible” file, meaning that unless you work at it, you won’t see the file listed. To see the file, make sure your FTP client has “View Invisibles” turned on. This varies from client to client, but often there is a “View” pulldown menu item that will let you toggle this setting.
- Once you can see the .htaccess file, open it up with your text editor. (Depending on your set up, you may have to download it first and then edit it.)
- Delete the WordPress generated rewrite code, which is everything from #Begin WordPress to #End WordPress.
- Replace it with the code above.
- Save the changes. (If you downloaded the file to edit it, remember to upload it and overwrite the old file.)
I hope you have as much luck with this as we did.
Speed is Officially a Factor in Google Rankings
It was recently announced that one of the new factors Google takes into consideration for ranking a website is how quickly the pages load. With this in mind, these types of tweaks can have more impact than just making your readers a bit happier. Take a look at our complete guide to speeding up a website for an expanding list of tips to optimize your load time.





Holy smokes Batman! That is freaking AWESOME. I can’t believe I never thought to do that, but its no surprise that it was jdMorgan’s idea.. He’s literally the guy I goto when I am stumped on htaccess.
+1 for you for recognizing the value of this trick, literally 50% would be an under-exaggeration on a super optimized blog. I mean this comes into play for 90% of every http packet sent! Thanks a lot for sharing..