.htaccess not working

Sometimes in case of a new web server installation, you may find that Apache does not use your .htaccess in your Virtual server directory.

This is because of your default server configuration which has to be adapted to load .htaccess directives. You need to edit the file:

/etc/apache2/sites-available/default

 

For example, a virgin server directive may resemble:

[[email protected]] /var/www #cat /etc/apache2/sites-available/default
<VirtualHost *:80>
        ServerAdmin [email protected]

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

You need to modify it by changing the following lines:

 
                Options FollowSymLinks
                AllowOverride None
        [/code]
to:
 
                Options FollowSymLinks
                AllowOverride All
        [/code]
and:
 

                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all[/code]
to:
 

                AllowOverride All
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all[/code]

Alternately, a single line of sed can achieve this:

sed -i 's/AllowOverride\ None/AllowOverride\ All/g' /etc/apache2/sites-enabled/000-default

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.