How to Enable Rewrite Mode for Apache in Ubuntu?

By Hardik Savani May 1, 2024 Category : Ubuntu Apache

Hello Dev,

In this example, I will show you enable rewrite mode in ubuntu. We will look at an example of enable mod_rewrite in linux. If you have a question about enable rewrite engine apache ubuntu then I will give a simple example with a solution. let’s discuss about enable mod_rewrite apache.

In this article, i will give you solution of "he requested url was not found on this server" in your php laravel project. some days ago i was working with my laravel project and i deploy project on digitalocean server. everything working fine only i have issue when i am trying to access direct route. there was a index.php overwrite issue. let me show you example and there is a three way to solve it.

Working Fine

https://example.com/

Not Works

https://example.com/contact-us

but bellow url working fine with index.php path.

https://example.com/index.php/contact-us

but let's remove index.php file, and make it works. let's see.

Solution 1: Enabling mod_rewrite

you can enable your mod_rewrite by using following command. let's run bellow command:

sudo a2enmod rewrite

now let's restart apache server with bellow command:

sudo systemctl restart apache2

Now, it will works, but if not works then you can try second solution.

Solution 2: Default Apache Configuration Permission

here, you need to give default Apache configuration permission using Directory tag, so you can open bellow file with command:

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

now let's update that file:

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

<VirtualHost *:80>

....

<Directory /var/www/html>

Options Indexes FollowSymLinks MultiViews

AllowOverride All

Require all granted

</Directory>

</VirtualHost>

now let's restart apache server with bellow command:

sudo systemctl restart apache2

Still not work then go for third solution here.

Solution 3: Default Apache Conf File

Here, you have to go on /etc/apache2/apache2.conf file and give AllowOverride all permission. you can open that file and replace bellow content.

sudo nano /etc/apache2/apache2.conf

now let's update that file:

/etc/apache2/apache2.conf

<Directory /var/www/>

Options Indexes FollowSymLinks

AllowOverride None

Require all granted

</Directory>

To

<Directory /var/www/>

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

</Directory>

now let's restart apache server with bellow command:

sudo systemctl restart apache2

I hope it can help you...

Thank you...

Tags :
Shares