3.TP5——如何给API接口的URL上增加版本号?

api.JhouShuai.com/3.0.0/ucenter/profile ---->api.JhouShuai.com/V300/ucenter/profile
api.JhouShuai.com/3.0.1/ucenter/profile ---->api.JhouShuai.com/V301/ucenter/profile

Nginx配置

server {
        listen  80;
        server_name zh.tp.com api.JhouShuai.com;
        set $root_path 'E:\zhou\public';
        root $root_path;

        index index.php index.html index.htm;
      
       
    
       #hide index.php
       location / {
          if (!-e $request_filename){
             rewrite ^/(\d)+\.+(\d)+\.+(\d)/(.*)$ /index.php/v$1$2$3/$4 last;
             break;
          }
       }
       


        location ~ \.php(.*)$  {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }

        location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {

        }

        location ~ /\.ht {
            deny all;
        }
 }

TP5,route.php配置

return [
    ':version/:controller/:function'=>'api/:version.:controller/:function'// 有方法名时
];

详细配置,项目目录结构

路由配置如图

你可能感兴趣的:(3.TP5——如何给API接口的URL上增加版本号?)