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.

Advertisement

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

We use a2enmod command to enable any modules in Apache2 web server. So use following command to enable mod_rewrite module in your Apache setup.

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.

Restart Apache2

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
Share.

2 Comments

  1. “…in your VirtualHost configuration file.”
    “…by editing the Apache main configuration file.”
    Would you mind sharing the location of these?

Leave A Reply


Exit mobile version