How to remove index.php from the url in laravel?

Member

by jasen , in category: PHP Frameworks , 4 months ago

How to remove index.php from the url in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by dalton_moen , 4 months ago

@jasen 

To remove index.php from the URL in Laravel, follow these steps:

  1. Open the .htaccess file located at the root of your Laravel project directory.
  2. Add the following code to the .htaccess file to remove index.php from the URL:
1
2
3
4
5
6
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>


  1. Save the changes to the .htaccess file.
  2. Make sure that Apache's mod_rewrite module is enabled. You can do this by running the following command in the terminal:
1
sudo a2enmod rewrite


  1. Restart the Apache web server by running the following command:
1
sudo service apache2 restart


  1. Test the URL without index.php to make sure it is working properly.


With these steps, you should now be able to access your Laravel application without index.php in the URL.