How To Remove index.php From Laravel Url

This is quite a common issue that can be caused by a few different things, all of which are very simple to fix.

If this is a fresh install then the first thing that you should check is your Apache conf file since this is likely the cause. Apaches conf file is usually located in “/etc/httpd/conf/httpd.conf”, but this may vary depending on your set-up. In this file you will need to modify the ‘Directory’ block on your virtual host. Update the contents of the directory block to contain the following

<Directory "/var/www/laravel/public">
     AllowOverride All

Your virtual host should look like this. Once you have added this to the conf file, save the file and restart Apache.

<VirtualHost *:80>
  DocumentRoot "/var/www/laravel/public
  <Directory "/var/www/laravel/public">
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all

Now you should now longer need to have index.php at the end of the url. If you have done the above and it still is not working then you will need to have a look at the rewrite rule in your .htaccess file to make sure it’s working correctly. If you do not have the mod_rewrite plugin installed then you will need to install it, but Im going to assume you have this installed since it is installed by default. The default .htaccess file generated by laravel contains some code that might be causing you issues. If you remove the following lines from your .htaccess the issue should immediately go away.

<IfModule mod_rewrite.c> <--remove
    <IfModule mod_negotiation.c> <--remove
        Options -MultiViews
    </IfModule> <--remove

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule> <--remove


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.