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 document root.
Some times you faced issues that 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 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 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 Apache2 server to reload all configuration to the running environment.
sudo systemctl restart apache2