2014-07-04 167 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>