我有一个API链接:
www.mydomain.com/api.php?key=test&action=say&what=hi
我想像访问它一样:
www.mydomain.com/api.php/test/say/hi
有可能吗?我没找到。
答案 0 :(得分:1)
如果您正在使用php修改API网址,那么您可以使用以下功能
<?php
//Suppose we have URL in string format
//$apiLink = 'www.mydomain.com/api.php?key=test&action=say&what=hi';
//if we doesn't know, or it will be dynamic all times getting from browser
$apiLink = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$sendNewUrl = makeNewURL($apiLink);
header("location: ".$sendNewUrl);
function makeNewURL($apiLink){
$totalParams = "";
$apiData = explode("?",$apiLink);
$apiParameters = explode("&",$apiData[1]);
if(count($apiParameters)>0){
foreach($apiParameters as $params){
if(strpos($params, '=') !== false){
$expected = explode("=",$params);
$totalParams .= $expected[1];
if($totalParams!=""){
$totalParams .= "/";
}
}
}
}
return $apiData[0]."/".$totalParams;
}