URL模式

2018-05-30 21:29 更新

ApiAdmin的URL模式使用兼容模式,當(dāng)然為了更好的使用API,我們也加入Web服務(wù)器重寫規(guī)則。

重寫配置

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

原理說明

當(dāng)我們訪問:http://localhost/admin/的時候,經(jīng)過重寫我們訪問的其實是http://localhost/index.php?s=/admin,再經(jīng)過ThinkPHP默認(rèn)類和函數(shù)的賦值,我們訪問的是http://localhost/index.php?s=/Admin/Index/index

當(dāng)我們訪問:http://localhost/api/{hash}的時候,經(jīng)過重寫我們訪問的其實是http://localhost/index.php?s=/api/{hash},再經(jīng)過我們的路由配置,我們訪問的其實是:http://localhost/index.php?s=/Home/Api/index/hash/{hash}

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號