Laravel路由除了root以外不起作用

Kev*_*gol 5 php apache .htaccess laravel

我一直在这个问题上花费数小时,希望找到自己的出路。我已经正确设置了laravel,创建了一个项目myapp

我的route.php文件仅包含

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

Route::get('/users', function()
{
    return 'Users!';
});
Run Code Online (Sandbox Code Playgroud)

当我跑步

http://localhost/myapp/public/
Run Code Online (Sandbox Code Playgroud)

我正确地获得了laravel起始页面

当我跑步

http://localhost/myapp/public/users
Run Code Online (Sandbox Code Playgroud)

我懂了

The requested URL /myapp/index.php was not found on this server.
Run Code Online (Sandbox Code Playgroud)

我不知道为什么要寻找index.php。

当我跑步

http://localhost/myapp/public/index.php/users
Run Code Online (Sandbox Code Playgroud)

我得到一个带有文本“用户”的页面。我应该在运行时获取此页面

http://localhost/myapp/public/users
Run Code Online (Sandbox Code Playgroud)

代替。

以下是我的.htaccess

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

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

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?在Linux上运行Apache。

ale*_*ell 5

RewriteBase设置为,/myapp/但您的index.php文件在/mayapp/public/吗?

因此,我认为您会发现RewriteBase需要/myapp/public/


Tom*_*Tom 0

在您的 application/config/application.php 文件中更改:

'index' => 'index.php',
Run Code Online (Sandbox Code Playgroud)

到:

'index' => '',
Run Code Online (Sandbox Code Playgroud)

这应该告诉 laravel 不要使用 index.php 并正确重写。

它适用于 Laravel 附带的标准 .htaccess 文件(尚未检查您是否修改了它)