ItSolutionStuff.com

How to Enable Rewrite Mode for Apache in Ubuntu?

By Hardik Savani β€’ May 1, 2024
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: Ubuntu
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

How to Increase upload_max_filesize in PHP Ubuntu?

Read Now β†’
β˜…

How to Check Current PHP Version in Ubuntu?

Read Now β†’
β˜…

How to Upgrade PHP Version from 8.0 to 8.1 in Ubuntu?

Read Now β†’
β˜…

How to Restrict/Block IP Address in Apache Ubuntu?

Read Now β†’
β˜…

How to Set Up Password Authentication with Apache in Ubuntu?

Read Now β†’
β˜…

How to Change PHP Version in Ubuntu Server?

Read Now β†’
β˜…

How to Install Phpmyadmin in Ubuntu Server?

Read Now β†’
β˜…

How to Install MySQL in Ubuntu Server?

Read Now β†’
β˜…

How to Install PHP in Ubuntu Server?

Read Now β†’
β˜…

How to Connect to a Remote Server using SSH on Ubuntu?

Read Now β†’
β˜…

How to Upgrade PHP Version from 7.4 to 8 in Ubuntu?

Read Now β†’
β˜…

How to Export Mysql Database using Command Line in Ubuntu?

Read Now β†’
β˜…

How to Upgrade PHP Version from 7.3 to 7.4 in Ubuntu?

Read Now β†’
β˜…

How to Enable Apache mod_rewrite Module in Ubuntu?

Read Now β†’