Tuning WordPress for Faster PageSpeed: Use Httpd.conf Instead of .htaccess for Permalinks

Tuning WordPress for Faster PageSpeed: Use Httpd.conf Instead of .htaccess for Permalinks featured image
(Last Updated On: December 13, 2017)

Looking to squeeze a little more speed out of your WordPress installation? Trying to drive an AWS micro instance beyond the realms of sensibility out of a spirit of good old-fashioned thriftiness?

Whatever you’re looking to achieve with WordPress, if you want to speed things up and you have root access to your server, one of the first things you can look to do is to make the mod_rewrites that little bit faster by turning off .htaccess support.

Why Turn Off .htaccess “Overrides”?

Quick answer: Speed of service! If you have the setting “AllowOverride All” set to your webroot folder (or, worse some directory higher up the chain) then every single folder apache looks in will first be scanned for an .htaccess file. Every. Single. Folder.

This is slower than never doing that. For a WordPress installation, it is also unnecessary as there is only one .htaccess file used by WordPress, in the root folder to tell apache how the pretty permalinks are to be formulated (and none at all if you’re not using pretty permalinks… but you like a good URL, so you’re using pretty permalinks, right?!).

How to Work Without .htaccess

One way to work without .htaccess if you are on a LAMP stack, and you have root access (i.e. if you have a VPS, dedicated server, or are using an Amazon EC2 instance to host WordPress) is to edit your httpd.conf file to set AllowOverride to None and to include your WP permalink .htaccess code here instead, in the “webroot” directory info, for example, assuming your webroot is /var/www/html/:

sudo -i
vi /etc/httpd/conf/httpd.conf

The above will allow you to edit your httpd.conf file. NOTE, be very careful if you are a novice here. Backup the working setup first. Then you should set the following where appropriate:

<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress
Order allow,deny
Allow from all

Remember, though, that once you’ve done this you need to save your file, exit vi, and restart apache to put your new settings into action, use the following to do this:
:wq [enter]
*** ABOVE COMMAND SAVES HTTPD.CONF, EXITS VI ***
service httpd restart

That done, you should navigate to your website and load a pretty permalinked page – if it works, you’re all set. If it returns some kind of error, you’ve done something wrong.

NOTE any update to your permalinks will now NOT automatically trigger an update to .htaccess (or, rather, it might, but your apache has been told not to respect these commands!).

Can W3 Total Cache .htaccess information Go in httpd.conf?

Yes. This website does just that. And it works. Just so we can say “it works” this website has been powered by a Micro AWS instance, and can serve a few thousand visitors per day. Note this is not recommended for production business websites running WordPress: if you receive regularly more than 2,000 visitors per day to your business website, chances are you can afford the performance boost of a more robust setup!

2 thoughts on “Tuning WordPress for Faster PageSpeed: Use Httpd.conf Instead of .htaccess for Permalinks

  1. Please note, this site more regularly fluctuates between EC2 medium and large instances. It was hosted on Micro only to prove it could be. We receive quite a lot of traffic (mainly to free tutorials like this one) these days, and the additional RAM and CPU to deal with all the concurrent requests helps to keep multiple users happy at the same time…

    But do leave a comment if the above has helped (or hindered) your efforts to drive WordPress a little bit faster – and give our caching a refresh in the process 😉

  2. July 1 2014 – this website now does not run on cloud instances at all, as it resides on a large dedicated machine in the UK, and is instead CloudFronted for fast, spikey, delivery around the globe. That’s a good value setup for a mid-sized pretty busy website!

    Let me know if you’d like the same for your business – particularly media – website, at a cost-effective price.

Leave a Reply

Your email address will not be published. Required fields are marked *

Silicon Dales