ApiAdmin的URL模式使用兼容模式,當(dāng)然為了更好的使用API,我們也加入Web服務(wù)器重寫規(guī)則。
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?s=$1 last;
}
//網(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}
更多建議: