How to use Commands Enable mod_rewrite in Ubuntu 22.04?

Jun 24, 2022 . Admin

Hi Guys,

Here, I will show you Ubuntu 22.04 on mod_rewrite Enable with Apache. I would like to share with you Steps to mod_rewrite Enable. let’s discuss about Commands mod_rewrite for Apache on Ubuntu 20.04. This article will give you simple example of Ubuntu 22.04 in Enable mod_rewrite. you will do the following things for Enable mod_rewrite with Apache.

You can use this post for ubuntu 14.04, ubuntu 16.04, ubuntu 18.4, ubuntu 20.04, ubuntu 21 and ubuntu 22.04 versions.

Use the simple steps below to enable / disable mod_rewrite on an Apache 2 server.

Step 1: Install Apache 2

Use the following command to install the Apache 2 web server

sudo apt-get update
sudo apt-get install apache2
Step 2: Enable mod_rewrite Apache By a2enmod Command

Type the a2enmod command to enable any modules in the Apache 2 web server:

sudo a2enmod rewrite
Step 3: Allow .htaccess File for VirtualHost

open your terminal and type the following command

sudo nano /etc/apache2/sites-available/000-default.conf

You need to add this "AllowOverride All" to your virtualhost configuration file as follows

<VirtualHost *:80>
    ServerName  www.example.com
    DocumentRoot /var/www/html
  
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
  
</VirtualHost>
Step 4: Restart Apache 2

Type the following command to restart the Apache 2 server

sudo systemctl restart apache2
#Ubuntu