我想创建一个很小的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