Laravel的Apache重定向失败

时间:2013-09-03 18:32:01

标签: apache .htaccess mod-rewrite laravel

我在Apache2上启用了mod_rewrite,在默认文件中启用了AllowOverride All。但是,当从Laravel给出pretty url时,Apache(重启后)似乎仍无法重定向。

WORKS(返回:用户!)localhost/laratest/public/index.php/users

不工作(404)localhost/laratest/public/users

我的.htaccess :(我也试过Documentation建议的那个无效)

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

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

Laravel routes.php:

Route::get('/', function()
{
    return View::make('hello');
});

Route::get('users', function()
{
    return 'Users!';
});

我在Ubuntu中使用默认的LAMP堆栈和配置。任何想法为什么这不起作用?

2 个答案:

答案 0 :(得分:1)

您是否已将RewriteBase设为/laratest/public

Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /laratest/public
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

答案 1 :(得分:0)

正如laravel网站(http://laravel.com/docs/installation#pretty-urls)所建议的那样尝试另一个:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]