Apache2’s .HTACCESS And Linode’s Linux Virtual Server

I was recently introduced to Linode, a cloud-based hosting company that provides instant deployment of Linux Virtual Servers. We partnered with RIA Labs in Brazil to re-launch websites for SAS Games, the Florida-based board game publisher of the popular TiViTz math strategy game, and RIA Labs was keen to use Linode for cloud-based hosting and Linux VPS.

The problem was, our partners in Brazil had a heck of a time getting SEO-friendly URLs to work in WordPress on Linode. The mod_rewrite module for Apache2 had been installed and was integrated and working as evidenced using PHP’s phpinfo(). But, the server didn’t seem to want to parse .HTACCESS files for redirect rules. Their developers were exhausted, so they turned to us for support in locating a solution.

SEO Friendly URLs On WordPress / Linode Linux VPS

After hours and hours of digging through Linode support forums, Apache2 configuration guidelines, .HTACCESS rules, and everything in-between, the solution was surprisingly simple: Linode’s virtual host configuration file was cannibalizing the server configuration and preventing .HTACCESS from being parsed. We had the correct settings in Apache2’s conf files, but alas Linode creates additional config files for each subdomain or virtual host on the server.

.HTACCESS URL Rewrites on a Linode Website

So, where to fix? There are two configuration files, plus one for every domain on your VPS, that need to be modified.

The first is located at /etc/apache2/apache2.conf. Make sure the AccessFileName for .HTACCESS is explicitly provided, remove any references to “AllowOverride None” found in the <Directory> block, and limit browser output for any .HTACCESS directive files using the <Files> block. Additionally, we want to enable the “FollowSymLinks” Option.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Make sure Apache2 is looking for .HTACCESS files
AccessFileName .htaccess
 
# Make sure the contents of those files are never output to the browser
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
 
# Make sure Apache allows AllowOverride (so .HTACCESS is parsed)
<Directory /var/www>
AllowOverride All
Options FollowSymLinks
</Directory>

The second configuration file is located at /etc/apache2/httpd.conf. Depending on your particular server settings, this file may be empty. If so, continue on to step three. But, if the file contains any configuration settings, be sure again that there are no references to “AllowOverride None“. Simply remove them, or change to “AllowOverride All” and be sure to again include “Options FollowSymLinks“:

1
2
3
4
5
# Make sure Apache allows AllowOverride (so .HTACCESS is parsed)
<Directory /var/www>
AllowOverride All
Options FollowSymLinks
</Directory>

Lastly, the virtual host files are found at /etc/apache2/sites-enabled/. This is the place that caused me so much confusion and headache. In each of the files that exist (there should be one for 000-default, and one for each domain or subdomain on your server) we need to again remove the “AllowOverride None” directive. Your untouched file will look something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<VirtualHost *:80>
     ServerAdmin you@yourdomain.com
     ServerName yourdomain.com
     DocumentRoot /var/www/
     ErrorLog /var/www/vhosts/yourdomain.com/logs/error.log
     CustomLog /var/www/vhosts/yourdomain.com/logs/access.log combined
 
	<Directory /var/www/>
        AllowOverride None
        Options Indexes MultiViews
        Order allow,deny
        allow from all
	</Directory>
</VirtualHost>

We again need to update the <Directory> block, removing the “AllowOverride None” directive, and making sure the “FollowSymLinks” option is included:

1
2
3
4
5
6
     [...]
	<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        Order allow,deny
        allow from all
	</Directory>