首页 > 代码库 > phpshe b2c商城系统配置nginx支持pathinfo和rewrite的写法

phpshe b2c商城系统配置nginx支持pathinfo和rewrite的写法

找到/usr/local/webserver/nginx/conf/nginx.conf文件(环境配置不一样,路径也可能不一样)

并在server {...省略掉的代码}中添加如下代码即可(如果程序放在根目录下用一级目录代码,放在二级目录,请用二级目录代码),改好后重启nginx:



###############开启pathinfo支持(如果已开启请忽略此处)##############

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


###############配置伪静态(一级目录下隐藏index.php)##############

if (!-e $request_filename) {
        ###程序放在一级目录下(如:http://www.phpshe.com/)
        rewrite ^/(.*)$ /index.php/$1 last;
}


###############配置伪静态(二级目录下隐藏index.php)##############

if (!-e $request_filename) {
        ###程序放在二级目录下(如:http://www.phpshe.com/shop/)
        rewrite ^/二级目录名/(.*)$ /二级目录名/index.php/$1 last;
}

phpshe b2c商城系统配置nginx支持pathinfo和rewrite的写法