The Apache mod_rewrite module is a rewriting engine based on defined rules. The Apache rewrite engine maps a URL to a directory path as well as to other URLs. In this tutorial, you will learn, how to enable the Apache mod_rewrite module and configure VirtualHost to use .htaccess files available under the document root.
Sometimes you faced issues the Apache server is not reading your .htaccess or Apache is not rewriting URLs while we are using correct rewrite rules in configuration files. This happens due to the Apache rewrite module is not being enabled. When we installed a fresh Apache server mod_rewrite is not enabled by default on your server, So to use rewrite configurations you need to manually enable the mode_rewrite module on your system.
Enable Apache2 mod_rewrite Module
sudo a2enmod rewrite
Enable .htaccess for VirtualHost
After enabling the Apache rewrite module, now you need to add “AllowOverride All” in your VirtualHost configuration file.
This setting can also be enabled globally by editing the Apache main configuration file.
Options Indexes FollowSymLinks
After enabling the mod_rewrite module in Apache you also need to reload the Apache2 server to reload all configurations to the running environment.
sudo systemctl restart apache2