nginx完美支持thinkphp3.2.2(需配置URL_MODE=>3 rewrite兼容模式)

浏览:9797 发布日期:2014/12/17 分类:技术分享 关键字: nginx
欢迎大家转载,请加上本页链接。

环境:nginx 1.6,thinkphp3.2.2

第一步,修改server块server {
    listen   80;
    server_name  www.domain.com domain.com;
    error_page   404              /404.html;
    error_page   500 502 503 504  /50x.html;
#这个location块处理动态资源请求.
    location ~  \.php   {
        root /data0/htdocs/www;
        fastcgi_pass   127.0.0.1:9000;
        include        fastcgi.conf;       
    }
    #这个location处理能处理所有的静态资源
    location / {
        root   /data0/htdocs/www;
        index  index.php index.html index.htm;
        #如果请求资源既不是静态目录资源(目录资源就是请求该目录下的默认首页index指令指定的默认资源),也不是静态文件资源时候,就需要脚本动态生成,重写后重新用第一个处理动态请求的location块处理。
        if (!-e $request_filename){
            #一定要用(.*)匹配整个URI,包含URI第一个字符反斜杠/
            rewrite ^(.*)$ /index.php?s=$1 last;
        }
    }
}
第二步:打开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。

注意不推荐用rewrite兼容模式,推荐用rewrite模式:
http://www.thinkphp.cn/topic/26657.html


最佳答案
评论( 相关
后面还有条评论,点击查看>>