文档中心 /部署运维

Nginx 伪静态

PATH_INFO 与重写规则的写法。

思路

伪静态的核心是把不存在的文件交给 index.php,同时让 /index.php/xxx 这种带路径信息的请求正确传给 PHP。

参考配置

location / {\n    try_files $uri $uri/ /index.php$is_args$args;\n}\n\nlocation ~ ^/(index|admin)\.php(/.*)?$ {\n    fastcgi_split_path_info ^(.+?\.php)(/.*)$;\n    try_files $fastcgi_script_name =404;\n    include fastcgi_params;\n    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n    fastcgi_param PATH_INFO $fastcgi_path_info;\n    fastcgi_pass 127.0.0.1:9000;\n}

常见坑

重复的 location / 会让首页之外的地址全部 404;fastcgi_split_path_info 必须留两个捕获组。

没找到答案?翻一翻文档中心,或者直接走联系方式。