THINKPHP NGINX配置伪静态(删除链接中的index.php和模块-控制器-方法)

首先来个NGINX的站点配置vhost
server {
listen 80;
server_name qingxinzui.com;
root /home/web/qingxinzui.com/public/;
location / {

index index.html index.php index.htm;
if (-e $request_filename) {
break;
}
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ ^.+.php($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;

}
}

最后在THINKPHP里
/application/route.php文件里
#添加::
use think\Route;
Route::get(‘:id’,’index/index/index’);

然后是
application/config.php文件里
设置自定义路由:
// 是否开启路由
‘url_route_on’ => true,
// 是否强制使用路由
‘url_route_must’ => false,

这时候,比如我们访问qingxinzui.com/abc,这时候,abc就会被识别为function index,即会执行到index/index/index方法
当然,由于我们使用的是Route::get()静态方法所以静态的请求参数也一样会保留,如果需要POST类型,直接修改为Route::post()

转载请写出处
thinkphp伪静态

发表评论