Home » Php » Laravel Redirect doesn't seem to work

Laravel Redirect doesn't seem to work

Posted by: admin November 30, 2017 Leave a comment

Questions:

When I run from the controller for www.mysite.com/login

return Redirect::to_action('profile');

it brings the user to www.mysite.com/index.php/profile

I’ve tried it with Redirect::to(‘profile’); but that doesn’t work either.
Redirect::home(); brings me to www.mysite.com/index.php which lead me to believe that my mod_rewrite was somehow not working but I have

RewriteEngine on

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

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

in the .htaccess under public.

Answers:

For Laravel to generate links minus the index.php prefix, you need to configure it correctly in addition to having the .htaccess file.

It’s easily overlooked, so make sure you’ve set 'index' => '', in your application/config/application.php. It’s on line 42 in the default config.