URL模式

2018-05-30 21:29 更新

ApiAdmin的URL模式使用兼容模式,当然为了更好的使用API,我们也加入Web服务器重写规则。

重写配置

  1. Nginx重写配置
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php?s=$1 last;
    }
  2. Apache重写配置
    //网站跟目录加入.htaccess文件就可以,配置如下
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?s=$1 [L]

原理说明

当我们访问:http://localhost/admin/的时候,经过重写我们访问的其实是http://localhost/index.php?s=/admin,再经过ThinkPHP默认类和函数的赋值,我们访问的是http://localhost/index.php?s=/Admin/Index/index

当我们访问:http://localhost/api/{hash}的时候,经过重写我们访问的其实是http://localhost/index.php?s=/api/{hash},再经过我们的路由配置,我们访问的其实是:http://localhost/index.php?s=/Home/Api/index/hash/{hash}

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号