Enabling mod_rewrite in Apache


This post is a bit geekier than usual but I have to share it because it’s something that was a bit frustrating until it was resolved.

I built a simple LAMP server at Linode this week and was testing out a WordPress site on it. Everything worked fine aside from the links, which was more than a minor frustration. My custom permalink structure is as follows:

I have the same permalink structure on my other servers. Nothing crazy.

My /var/www/ directives were as follows:

Options -Indexes +FollowSymLinks -MultiViews
AllowOverride None
Order allow,deny
allow from all

So that wasn’t the issue. My .htaccess file was in place:

# BEGIN WordPress

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

# END WordPress

My /var/www/ directory was chowned to www-data:www-data as well.

Still no dice. As it turned out (yes, I’m intentionally skipping over the weeping and gnashing of teeth), mod_rewrite (the Apache module responsible for URL rewriting) wasn’t enabled.

The fix? Running these commands:

# a2enmod rewrite
Enabling module rewrite.
Run '/etc/init.d/apache2 restart' to activate new configuration!
# /etc/init.d/apache2 reload
Reloading web server config: apache2.

That’s it! My “pretty” permalinks now work on the server. Whew.