今天配置路由的時候,只有原來的自帶路由可用:
Route::get('/', function()
{
return View::make('hello');
});
再網上搜索了辦法:來自:http://www.jsjtt.com/webkaifa/PHP/102.html
最近在使用php laravel框架的時候 在routes.php文件中添加路由,老是出現404錯誤,如圖
使用跟目錄可以訪問 Route::get('/', 'HomeController@showWelcome');
如果非跟目錄就會出現404 頁面找不到的錯誤,如下
Route::get('user', 'UserController@index');
解決方法:
1.在apache conf開啟rewrite模塊,把下面這句話前面的#去掉。
LoadModule rewrite_module modules/mod_rewrite.so
2.在conf文件中找到directory 把AllowOverride None 改成 AllowOverride All
<Directory "c:/Apache24/htdocs"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
3.在laravel項目工程的public目錄下添加.htaccess文件 ,文件內容如下
<IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>
然后重新apache服務重新訪問就可以運行了。
另外:自己在修改directory時候找錯位置了:應該是:<Directory "f:/server/Laravel_site/public"> 結果我該的卻是:<Directory "f:/server/Apache24/cgi-bin">
切記按步驟來