Execute in terminal
sudo a2enmod rewrite
After thedirective, the Mod_rewrite module is enabled.
Alternatively, you can turn on the Mod_rewrite module by connecting /etc/apache2/mods-available/rewrite.load to /etc/apache2/mods-enabled/rewrite.load. Use the command to operate:
sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
A little tip
In fact, when I adopted the above approach in Ubuntu and restarted the Apache service, I still could not rewrite the URL normally. Here, there is something else that needs attention:
sudo vim /etc/apache2/sites-enabled/000-default
Replace:
AllowOverride None
is modified to:
AllowOverride All
The /etc/apache2/sites-enabled/000-default above is actually the connection to /etc/apache2/sites-available/default. AllowwOverride None will completely ignore the .htaccess file, and naturally the rewrite rules defined in it will not take effect.
Finally, don’t forget to restart Apache using the following command:
sudo /etc/init.d/apache2 restart.