How to enable .htaccess in Apache HTTP server

.htaccess

A .htaccess file is a directory-level configuration file for Apache HTTP server, which allows one to override the web server’s system-wide settings without modifying the global configuration file (e.g., httpd.conf or apache2.conf). Things like per-directory access control, password protection, URL redirection or hotlink prevention can be configured in the .htaccess file.

You should avoid using file.htaccess completely if you have access to httpd main server config file. Using file.htaccess slows down your Apache HTTP server. Any directive that you can include in a .htaccess file is better to set in a Directory block, as it will have the same effect with better performance.

Details about .htaccess can be found here.

Enabling

By default, .htaccess isn’t available. To enable it you will need to edit the configuration file.

Edit file  /etc/apache2/sites-available/arso.us.to.conf 
looks something like this:

#  /etc/apache2/sites-available/arso.us.to.conf
<VirtualHost *:80>
    ServerName arso.us.to
    ServerAlias www.arso.us.to
    DocumentRoot /var/www/html/arso
    <Directory /var/www/html/arso>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all 
    </Directory>
</VirtualHost>

add or change line 8 to AllowOverride All and if you have mod_rewrite loaded that’s all. 

Rewrite module

To enable rewrite module, run:

sudo a2enmod rewrite
sudo service apache2 reload

Leave a Comment

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