How to Enable Apache mod_rewrite Module in Ubuntu?

By Hardik Savani May 1, 2024 Category : Apache

Hi Guys,

Here, i will show you how to rewrite urls with mod_rewrite for apache on ubuntu. This tutorial will give you simple example of how to enable mod_rewrite in linux server. you'll learn apache enable mod_rewrite virtual host. This post will give you simple example of the requested url was not found on this server php larave.

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