情景:
访问 http://www.alan.com/name/alan
时指向 http://www.alan.com/index.php/name/alan
方法:
在nginx配置文件nginx.conf中添加:
location / {
if ( !e $request_filename ) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
如果项目入口文件在一个子目录中:
location / {
if ( !e $request_filename ) {
rewrite ^/目录/(.*)$ /目录/index.php/$1 last;
}
}
注:
1.-e和!-e用来判断是否存在文件或目录
2. if后面要有一个空格,否则nginx可能会重启失败
资料:【nginx,apache】thinkphp ,laravel,yii2开发运行环境搭建http://www.54php.cn/default/192.html