Laravel Redirect redirects URL to index.php

One of the first things that I do when I start using a new framework (CodeIgniter, Laravel etc) is to remove the default index.php from the URL.

When you install Laravel and you want to remove index.php from the URL simply do this (If you are using Apache, make sure that mod_rewrite is enabled):

Create .htaccess file in your public directory and add this:

<IfModule mod_rewrite.c>
     RewriteEngine on

     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d

     RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Many developers do this and forget that there is another step. Everything works fine until you use Laravel’s Redirect class, for example:

return Redirect::to ('someurl'); 

This redirects you to index.php/someurl instead of someurl.

What you need to do is to open application/config/application.php file and you will see this on the line 42:

'index' => 'index.php'

Remove index.php so it becomes

'index' => ''

Save the file and now you have a cleaner, nicer URLs without the index.php.