Route::get('hello',function(){
return 'Hello World!';
});
在laravel/app/Http/routes.php下添加上面的語句,然后再瀏覽器中使用localhost/laravel/public/hello
,用Apache來運行,會報404錯誤,后來在網上查了資料,發現是URL重定向的問題,具體的解決方法如下:
1,php開啟phpopenssl
2,在apache conf開啟rewrite莫塊
模塊(#LoadModule rewrite_module modules/mod_rewrite.so)
3,在conf文件中找到directory 把AllowOverride None 改成 AllowOverride All
<Directory>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
4,在laravel項目工程的public目錄下添加.htaccess文件 ,文件內容如下
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
5、restart以下Apache服務器就沒問題了。