Nginx下使Thinkphp URL模式支持PATHINFO和REWRITE

1.支持PATHINFO

找到location ~ \.php {   ,把$去掉,并在里面加上这两句:
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;

location ~ \.php { #去掉$
            root       html
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_split_path_info ^(.+\.php)(.*)$;       #添加
            fastcgi_param PATH_INFO $fastcgi_path_info;    #添加
        }

2.支持REWRITE去掉index.php

找到location / {  在里面加上:
if (!-e $request_filename) {
   rewrite  ^/(.*)$ /index.php?s=$1 last;
   break;
}

location / {
            root       html 
            index  index.html index.htm index.php;

            if (!-e $request_filename) {                  #添加
                   rewrite  ^/(.*)$ /index.php?s=$1 last; #添加
                   break;                                 #添加
            }                                             #添加
        }

如果thinkphp不是部署在网站根目录下,即需要把

rewrite  ^/(.*)$ /index.php?s=$1 last;
改成
rewrite  ^/子目录/(.*)$ /子目录/index.php?s=$1 last;

如果根目录下有多个项目的话,可以写多个rewrite:

 if (!-e $request_filename) {
      rewrite  ^/项目1/(.*)$ /项目1/index.php?s=$1 last;
      rewrite  ^/项目2/(.*)$ /项目2/index.php?s=$1 last;
      rewrite  ^/项目3/(.*)$ /项目3/index.php?s=$1 last;
      break;
 }
 3.支持PATHINFO前提下REWRITE隐藏index.php
设TP5项目目录为:/activity2/public/
location /activity2/public/ {
    if ( !-e $request_filename) {
        rewrite ^/activity2/public/(.*)$ /activity2/public/index.php/$1 last;
        break;
    }
 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值