Laravel的路由使用起来非常便利,在laravel5安装文件夹下,app/http/routes.php中添加。
如
Route::get('user', function () {
return "Hello World!";
});
那么以get方法访问 http://localhost/user 时,就会调用回调函数function()。
初次使用的时候,报错,404 not found, 显示服务器上没有/user;
查了一下才知道用Apache作为laravel的服务器时,要开启mod_rewrite。
修改apache/conf/httpd.conf文件,
定位到
#LoadModule rewrite_module modules/mod_rewrite.so
去掉注释;
再定位到
... ...
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride NONE
... ...
把NONE改成ALL。
如此一来路由就可以生效了。
虽然对这种设计思想还算明了(理解RESTful架构),但很想搞清楚其具体是怎么实现的。
【mod_rewrite】以下摘自百度百科