By default, Ubuntu 13.04 doesn’t enable the rewrite engine module after installing Apache. The rewrite engine for Apache allows for on-the-fly URL rewriting/changing. This allows for the use of urls that are human readable, and SEO friendly. The rewrite engine is capable of capturing a website request, running it through a series of expression checks, and if a match is found, it will pass on the rewritten request to the web server. The end user would not notice anything different within their web browser, other than perhaps easier to read urls. The rewrite engine is great for re-directions, and is a requirement for some CMS packages such as Drupal.
This guide assumes that Apache is already installed on your machine. If it not installed, please install it first using the command “sudo apt-get install apache2″
Follow the steps below to enable the rewrite engine.
Enable the rewrite module using the command “sudo a2enmod rewrite”
Depending on which website you want the rewrite engine to work on, you may need to modify the Apache configuration files some more.
For the default website, open up the “/etc/apache2/sites-available/default” file in your favorite editor. I am using “nano” for this example
The file should look something like the image below. The lines you will need to focus on are the ones that start with “AllowOverride”.
You need to change the “AllowOverride None” to be “AllowOverride All” for the directories you want the rewrite engine to work in. There are other options that can be used for the AllowOverride feature, but I won’t be going into the details of those in this article.
Exit the editor, and Save the file.
Restart Apache using “sudo /etc/init.d/apache2 restart”
If Apache hasn’t been configured for a ServerName option yet, you may get the above error message, or something similar. This isn’t a huge concern, and can be resolved later.
You should now be able to create .htaccess files, and use them how you want.