nginx不支持pathinfo函数

server {

        listen 80;

        server_name www.domain.com domain.com;

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;



        location ~ \.php {

                root /data0/htdocs/www;

                fastcgi_pass 127.0.0.1:9000;

                #包含nginx服务器传递给fastcgi程序的参数,php中通过$_SERVER['参数名']可获取

                include   fastcgi.conf;

                #定义变量$fastcgi_script_name_new赋值为$fastcgi_script_name变量

                set $path_info "";

                set $fastcgi_script_name_new $fastcgi_script_name;

                if ($fastcgi_script_name ~*  "^(.+\.php)(/.+)$") {

                        set $fastcgi_script_name_new $1;

                        set $path_info $2;

                }

                        #对fastcgi.conf中的SCRIPT_FILENAME和SCRIPT_NAME fastcgi参数进行重写

                        fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name_new;

                        fastcgi_param   SCRIPT_NAME   $fastcgi_script_name_new;

                        #定义一个新的nginx服务器传递给fastcgi的参数PATH_INFO,thinkphp需要这个参数

                        fastcgi_param   PATH_INFO $path_info;

        }



        location / {

                root /data0/htdocs/www;

                index  index.html index.htm;

                if (!-e  $request_filename){

                        rewrite ^(.*)$ /index.php$1 last;

                }

        }

    }

tp支持PHPinfo

 

第二步:打开thinkphp框架的配置文件convention.php,

修改URL_MODEL=>1,采用pathinfo模式,别设置成2啊,因为nginx重写加上了index.php入口文件了。

第三步:在浏览器输入:www.domain.com,结果如下:

:)

欢迎使用 ThinkPHP!

[ 您现在访问的是Home模块的Index控制器 ]

第四步:在浏览器中输入URL时候,用rewrite形式的url,就是不要输入入口文件了,其它的不变和pathinfo模式一样,例如:
http://www.domain.com/module/controler/action/参数1/值1/参数2/值2/

网址中不再需要输入入口文件index.php了,因为在刚才重写时我们已经指定好了入口文件index.php。

 

 

第二步:打开thinkphp框架的配置文件convention.php,

修改URL_MODEL=>3,采用rewrite兼容模式,并且修改
'VAR_PATHINFO'=> 's', 重写时我们用的是s=""的形式.

第三步:在浏览器输入:www.domain.com,结果如下:

:)

欢迎使用 ThinkPHP!

[ 您现在访问的是Home模块的Index控制器 ]

第四步:在浏览器中输入URL时候,还是用rewrite形式的url,就是不要输入入口文件了,其它的不变,例如:
http://www.domain.com/module/controler/action/参数1/值1/参数2/值2/

网址中不再需要输入入口文件index.php了,因为在刚才重写时我们已经指定好了入口文件index.php。

你可能感兴趣的:(nginx)