我想創建一個很小的API, 我有一個文件夾,我有index.php
和.htaccess
內一個名爲API文件夾中我所試圖做的是當我訪問api/something
到最後一個參數變換到api/?x=something
併爲您在PHP函數是否存在something
如果沒有顯示404的.htaccess URL,以獲取參數
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ index.php?x=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ index.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ index.php [QSA,NC,L]
</IfModule>
如果訪問api
文件夾,它的工作原理,但如果把它叫做我添加api/something
沒有。
如果是很重要的: 文件夾的結構是這樣的: root_website_folder/sub_folder/api
當重寫「東西」給x=something
我得到的x
到FUNC調用是否存在
public function init(){
$func = strtolower(trim(str_replace("/", "", $_REQUEST['x'])));
var_dump($func);
if((int)method_exists($this,$func) > 0){
$this->$func();
}else{
$this->response('', 401);
}
}
時發生了什麼你去**/api/something/**? – starkeen
@starkeen它顯示404 – Froxz
您是否可以澄清當您導航到'/ api /?x = something'應該進一步重寫時您期望發生的事情? – apokryfos