Nov 10, 2018

How to enable rewrite module redirect of Apache2 on Ubuntu

First enable rewrite module:

$ sudo a2enmod rewrite

In /etc/apache2/apache2.conf, find

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

And change AllowOverride None to All and save.

Restart apache:

$ sudo service apache2 restart

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

To use Directory block without using .htaccess:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
        RewriteEngine On
        RewriteRule ^i88/?(.*)$ "http\:\/\/it\.i88\.ca\/test\/$1" [R=301,L]
</Directory>