MAMP 中的 nginx 默认是没有开启 pathinfo 模式的,直接修改 nginx 配置文件也会被覆盖掉,我们可以在面板的 try_files 和 custom 中设置。
try_files 中填写如下配置开启 index.php 隐藏模式
$uri $uri/ /index.php/$uri$is_args$args
custom 中填入如下规则
location ~ \.php(.*)$ {
# unix sock 要根据你选用的 php 版本做相应修改
# ps -ef | grep nginx 可以看到 nginx 启动加载的配置文件
# 配置文件中含有你当前 vhost 的配置段 可以看到对应的 unix sock
fastcgi_pass unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI_php5.6.40.sock;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /Applications/MAMP/conf/nginx/fastcgi_params;
}
保存后框架就可以使用 pathinfo 模式了。