2016-05-15 825 views
0

使用Laravel Framework 5.2.31版和Apache/2.4.12(Ubuntu)服務器。得到以下錯誤信息:Laravel 5.2.31:routing:404 not found錯誤信息

404 Not Found在此服務器上找不到請求的URL/laravel/public/signup。

謝謝你的幫助。

下面是routes.php文件(該文件不再準確。請參閱編輯部分下方新建一個)

<?php 

Route::group(['middleware' => ['web']], function() 
{ 
    Route::get('/', function() 
    { 
     return view('welcome'); 
    }); 
    Route::post('/signup', [ 
     'uses' => '[email protected]', 
     'as' => 'signup' 
    ]); 
}); 

下面是UserController.php文件

<?php 

namespace App\Http\Controllers; 
use Illuminate\Http\Request; 

class UserController extends Controller 
{ 
    public function postSignUp(Request $Request) 
    { 
     $email = $request['email']; 
     $prenom = $request['prenom']; 
     $motDePasse = bcrypt($request['motDePasse']); 

     $user = new User(); 
     $user->email = $email; 
     $user->prenom = $prenom; 
     $user->motDePasse = $motDePasse; 

     $user->save(); 

     return redirect()->back(); 
    } 

    public function postSignIn(Request $Request) 
    { 

    } 
} 

編輯

以下是routes.php

<?php 

Route::get('/', function() 
{ 
    return view('welcome'); 
}); 
Route::post('/signup', [ 
    'uses' => '[email protected]', 
    'as' => 'signup' 
]); 

下面是RouteServiceProvider.php

<?php 

namespace App\Providers; 

use Illuminate\Routing\Router; 
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; 

class RouteServiceProvider extends ServiceProvider 
{ 
    /** 
    * This namespace is applied to your controller routes. 
    * 
    * In addition, it is set as the URL generator's root namespace. 
    * 
    * @var string 
    */ 
    protected $namespace = 'App\Http\Controllers'; 

    /** 
    * Define your route model bindings, pattern filters, etc. 
    * 
    * @param \Illuminate\Routing\Router $router 
    * @return void 
    */ 
    public function boot(Router $router) 
    { 
     // 

     parent::boot($router); 
    } 

    /** 
    * Define the routes for the application. 
    * 
    * @param \Illuminate\Routing\Router $router 
    * @return void 
    */ 
    public function map(Router $router) 
    { 
     $this->mapWebRoutes($router); 

     // 
    } 

    /** 
    * Define the "web" routes for the application. 
    * 
    * These routes all receive session state, CSRF protection, etc. 
    * 
    * @param \Illuminate\Routing\Router $router 
    * @return void 
    */ 
    protected function mapWebRoutes(Router $router) 
    { 
     $router->group([ 
      'namespace' => $this->namespace, 'middleware' => 'web', 
     ], function ($router) { 
      require app_path('Http/routes.php'); 
     }); 
    } 
} 

回答

1

首先,好像你正在使用post方法routes.php,但你嘗試加載使用get方法的路線。

其次,這是您的網絡服務器配置錯誤。您的Laravel項目的Web服務器should be pointed to a public directory(您應該爲其創建VirtualHost並重新啓動Web服務器)。

另外,從routes.php刪除web中間件,因爲it will cause errors

+0

我已經根據您提供的鏈接編輯了文件'route.php'。我在我的服務器上檢查了'RouteServiceProvider.php'文件;其內容與此處的一個內容相同[link] https:// github。com/laravel/laravel/commit/5c30c98db96459b4cc878d085490e4677b0b67ed#diff-b467cc786635bd6945b17726282f1c64 [/ link]仍然顯示錯誤信息'404 page not found'。 – user5293879

+0

你從我的回答中做了其他兩件事嗎? –

0

它添加到的.htaccess

RewriteEngine On 
RewriteRule ^(.*)$ public/$1 [L] 

,並更改路徑:

打開本地/引導/ paths.php

'public' => __DIR__.'/../public', to 'public' => __DIR__.'/../../', 

打開本地/引導/ paths.php和找到下面的代碼

'public'=>DIR '/ .. /公共', 變化與下面碼

'公共'=>DIR。 '/ ../.. /',

Open index.php (on root) and find below code 

require __DIR__.'/../bootstrap/autoload.php'; 
$app = require_once __DIR__.'/../bootstrap/start.php'; 

變化與下面碼

require __DIR__.'/local/bootstrap/autoload.php'; 
$app = require_once __DIR__.'/local/bootstrap/start.php'; 

現在你已經全部設置你可以訪問url http://example.com/如果仍然有問題嘗試清除緩存瀏覽器。

+0

我使用Apache/2.4.12。該行已在'/ etc/apache2/mods-enabled'中取消註釋爲'LoadModule rewrite_module/usr/lib/apache2/modules/mod_rewrite.so' – user5293879

+0

我正在更新我的解決方案。看看它是否有效。 –