Nginx下配置ThinkPHP的URL Rewrite模式和pathinfo模式支持

前面有关于lnmp环境的搭建,在此就不在赘述。下面就简述thinkPHP如何在nginx下开启url_rewrite和pathinfo模式支持

主要有两个步骤:

一、更改php.ini将;cgi.fix_pathinfo=0  改为cgi.fix_pathinfo=1

二、更改nginx配置文件中php的location设置pathinfo模式:

location ~ \.php {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include fastcgi.conf;
}

#nginx rewrite配置:

location / {
root html;
index index.html index.htm;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}

如果你的thinkphp安装在二级目录下则rewrite配置如下:

#yourdomain是所在的目录名称

location /yourdomain/ {
if (!-e $request_filename){
rewrite ^/yourdomain/(.*)$ /yourdomain/index.php?s=$1 last;
}
}

posted @ 2016-05-15 22:52  selfim  阅读(541)  评论(0编辑  收藏  举报