How to enable index.php rewrite mode in Apache Ubuntu 18.04?

Ubuntu

Nicesnippets

2556

07-01-2021


Hi Guys,

Today,I will learn you how to enable index.php rewrite mode in Apache Ubuntu 18.04. The apache Mod_rewrite is very popular for rewriting human-readable URLs in dynamic websites. This makes the URL’s look cleaner and SEO friendly on websites.We will show you how to enable the Apache 2 mod_rewrite module and configure it for use .htaccess files available with apache ubuntu web server.If you are installed the lastest Apache 2 server. At that time mod_Rewrite module is not enabled by default on apache 2. So, you can use the below given easy steps and enable/activate mod_rewrite in apache 2 server within minutes.

Here, I will show you step by step enable index.php rewrite mode in Apache Ubuntu 18.04 bellow.

Step 1: Install Apache 2


In this step,If you are not installed apache 2 in ubuntu. So, you can use the following command to install apache 2 web server.

sudo apt-get update

sudo apt-get install apache2

Step 2: Enable mod_rewrite Apache By a2enmod Command

Now this step, If you want to enable mod_rewrite apache in ubuntu. So, you can connect your instance or web server to ssh terminal. And then type a2enmod command to enable any modules in Apache 2 web server.

sudo a2enmod rewrite

Step 3: Allow .htaccess File for VirtualHost

Here this step,Then you need to add this “AllowOverride All” in your VirtualHost configuration file.

Note: The main reason is to enable or allow .htaccess file in the Apache server. Because it does not allow by default. So, you can not use of ‘.htaccess’ file.

Now,open your terminal and type the following command.

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

Then you need to add this “AllowOverride All” in your VirtualHost configuration file like below.

<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

Last in this step, You need to restart Apache 2 server to restart all configuration to the running environment.

sudo systemctl restart apache2

It will help....