.htaccesslaravel-4redirect-loop

Redirect Loop with Laravel 4


I have this installed on my local machine. Laravel is installed at the root of a vhost folder, and the document root is the public folder. If i just go to the root url everything is fine. Howerver if I specify a route then I get a redirect loop. For example www.example.com works, but www.example.com/admin causes a loop. Here's my .htaccess:

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

    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>

Here's my routes.php file:

Route::get('/', function()
{
    return 'Hello World';
});

Route::get('testroute',function(){
    return 'Hello World';
});

Route::controller('admin','AdminController');

Here's my AdminController.php controller file:

<?
class AdminController extends BaseController {

    public function getIndex(){
        return View::make('admin');
    }
}
?>

Solution

  • Found the problem. Because the document root wasn't the root of the Virtual Host I needed to add this to the .htaccess:

    RewriteBase /