Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP API在REST实现中不起作用_Php_.htaccess_Api_Rest - Fatal编程技术网

PHP API在REST实现中不起作用

PHP API在REST实现中不起作用,php,.htaccess,api,rest,Php,.htaccess,Api,Rest,我正在尝试使用PHP构建一个简单的RESTful API。该请求与URL路径中的普通查询一起工作,但是,在实现REST方法时,我遇到了一个“404URL未找到”错误 .htaccess Options +FollowSymlinks RewriteEngine On RewriteRule ^([a-zA-Z|_-]*)$ index.php?name=$1 [nc,qsa] index.php(代码段) 引述: I did some more debugging, and I found

我正在尝试使用PHP构建一个简单的RESTful API。该请求与URL路径中的普通查询一起工作,但是,在实现REST方法时,我遇到了一个“404URL未找到”错误

.htaccess

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([a-zA-Z|_-]*)$ index.php?name=$1 [nc,qsa]
index.php(代码段)

引述:

I did some more debugging, and I found out that /api/Grill(my) does not work, 
maybe due to parentheses in the name? Because /api/Pasta works

正则表达式中没有括号,所以它不匹配


你的URL语法计划是什么?可以帮助您使用正则表达式使其工作。

您发送的导致404的URL是什么?我更喜欢使用Framework,我做了一些调试,发现/api/Grill(my)不工作,可能是因为名称中的括号?因为/api/api在正则表达式中没有括号,所以它不匹配。你的URL语法计划是什么?可以帮助您使用正则表达式使其工作。将其转化为一个答案,因为我认为如果没有更多信息,您将不会得到更好的答案-如果您需要更多帮助,请将其放入注释中,我将为您更新我的答案。好的,现在我正在尝试让正则表达式为我提供多个变量:RewriteRule^additem/(*)/*(*)/*(*)(*)/*(.*)/*(.*)/*(.*)/*(.*)/*(.*)/*(.*)/*$additem.php?name=$1&desc=$2&price=$3&isVeg=$4&isHot=$5&isNuts=$6&isgrant=$7&thumb=$8&cat=$9有什么方法可以让这个工作,或者更好的替代方法吗?字符将匹配所有内容,包括前斜杠,如果有人放进去,它将搞乱url的读取方式,或者可能只是其中的/。我会为URL的每一部分指定实际的字符集,否则就没有更好的替代方法了,afaikYepp,最后用([0-9A-Za-z]+)表示字符串,([0-9]+)表示数字,效果很好。我不喜欢事先不查阅任何阅读材料。
I did some more debugging, and I found out that /api/Grill(my) does not work, 
maybe due to parentheses in the name? Because /api/Pasta works