2014-07-04 123 views
1

我是新来laravel。在我的项目路线工作不正常。我已经提到很多答案,但没有任何作用。在我的项目我路线是遵循路线不工作laravel 4.2

Route::get('/',array('uses'=>'[email protected]')); 
    Route::get('first',array('uses'=>'[email protected]')); 

控制器 ..

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] 

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

回答

0

你需要做以下的事情:

  1. 第一复制根目录中公共目录的所有内容,即将公用文件夹1的内容提高一级。

  2. 修改的index.php
    的内容从=> “要求__DIR __ '/ .. /引导/ autoload.php';
                               “$ app = require_once __DIR __。'/ ../bootstrap/start.php';

To =>“要求DIR。'/ bootstrap/autoload。PHP';”
                  “$应用= require_once DIR。 '/引导/ start.php';自举”

并且还内容/ paths.php

从=> “'公共'=> __DIR __。 '/ ../.. /',
要=>“'公共'=> __DIR __。 '/ ..',

3.然后最后在您的根目录下创建.htaccess文件并写入此文件。

< IfModule mod_rewrite.c>
< IfModule mod_negotiation.c>
选项-MultiViews
</IfModule>配置
RewriteEngine叙述在
重写规则^(。*)/ $/1 $ [L,R = 301]
的RewriteCond%{REQUEST_FILENAME}!-d
的RewriteCond%{REQUEST_FILENAME}!-f
重写规则^的index.php [L]
</IfModule>