How to Enable Rewrite Mode for Apache in Ubuntu?
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Increase upload_max_filesize in PHP Ubuntu?
- How to Check Current PHP Version in Ubuntu?
- How to Upgrade PHP Version from 8.0 to 8.1 in Ubuntu?
- How to Restrict/Block IP Address in Apache Ubuntu?
- How to Set Up Password Authentication with Apache in Ubuntu?
- How to Change PHP Version in Ubuntu Server?
- How to Install Phpmyadmin in Ubuntu Server?
- How to Install MySQL in Ubuntu Server?
- How to Install PHP in Ubuntu Server?
- How to Connect to a Remote Server using SSH on Ubuntu?
- How to Upgrade PHP Version from 7.4 to 8 in Ubuntu?
- How to Export Mysql Database using Command Line in Ubuntu?
- How to Upgrade PHP Version from 7.3 to 7.4 in Ubuntu?
- How to Enable Apache mod_rewrite Module in Ubuntu?