路线不适用于laravel 4.2

时间:2014-07-04 16:33:45

标签: .htaccess laravel-4 routing laravel-routing

我是laravel的新手。在我的项目中,路线无法正常工作。我已经提到了许多答案,但没有任何效果。在我的项目中,我的路线如下

    Route::get('/',array('uses'=>'maincontroller@index'));
    Route::get('first',array('uses'=>'maincontroller@first'));

我的控制器 ..

class MainController extends BaseController
{

    public function index()
    {
        return View::make('site.index');
    }

    public function first()
    {
        return View::make('site.firstpage');
    }}

我保存了我的视图文件。 当我给予

    localhost/gc/public/

它正确加载我的索引页面。但是当我给出

    localhost/gc/public/first 

它不起作用。它抛出一个错误

    Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

当我这样给出时

     localhost/gc/public/index.php/first.

它正常工作..但我需要正确的路由。

有人说我的.htaccess文件可能有问题。 我的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]

但我需要知道如何解决路由问题。

2 个答案:

答案 0 :(得分:0)

您的路线控制器名称需要与实际控制器匹配。

Route::get('/',array('uses'=>'MainController@index'));
Route::get('first',array('uses'=>'MainController@first'));

此外,如果您只需要uses属性,那么您可以像这样编写路线:

Route::get('/', 'MainController@index');
Route::get('first', 'MainController@first');

答案 1 :(得分:0)

您需要做以下事情:

  1. 首先复制根目录中公共目录的所有内容,即将公用文件夹1的内容升级。

  2. 修改index.php的内容 From =&gt; “需要__DIR __。'/ .. / bootstrap / autoload.php';

    $ app = require_once __DIR __。'/ .. / bootstrap / start.php';

  3. To =&gt; “要求 DIR 。'/ bootstrap / autoload.php';” “$ app = require_once DIR 。'/ bootstrap / start.php';”

    以及bootstrap / paths.php的内容

    From =&gt; “'public'=&gt; __DIR __。'/ .. / .. /',

    To =&gt; “'public'=&gt; __DIR __。'/ ..',

    3.然后在根目录中最终创建 .htaccess 文件并写下来。

    &lt; IfModule mod_rewrite.c&gt;
        &lt; IfModule mod_negotiation.c&gt;
            选项-MultiViews
        &LT; / IfModule&GT;
        RewriteEngine On     RewriteRule ^(。*)/ $ / $ 1 [L,R = 301]
        RewriteCond%{REQUEST_FILENAME}!-d
        RewriteCond%{REQUEST_FILENAME}! - f
        RewriteRule ^ index.php [L]
    &LT; / IfModule&GT;

相关问题