Web 服务 - 一个 .htaccess RewriteRule,它采用双精度参数并将其发送到 PHP 中的 Web


web services - a .htaccess RewriteRule that takes to Double arguments and sends it to a webservice in php

我正在尝试在我的.htaccess文件中编写一个RewriteRule,以便它接受两个双参数(纬度和经度)并重定向到php Webservice控制器,并将这些参数作为GET变量。

到目前为止,在这个答案的帮助下,我得到了这个规则:

RewriteRule ^api/geopointsnearlocation/(/^-?(?:'d+|'d*'.'d+)$)/(/^-?(?:'d+|'d*'.'d+)$)/$   api/GeoPointsRestController.php?lat=$1&lng=$2 [nc,qsa]

但是当我使用此网址时:

http://localhost/api/geopointsnearlocation/29%2E9876/50%2E8765/

要调用我的网络服务,我收到以下错误消息:

未找到请求的 URL/api/geopointsnearlocation/1.2/2.3/ 在此服务器上。

此外,404 未找到错误是 尝试使用错误文档处理 请求。

我试图将数字传递为29.987629,但它们都不起作用。我猜我的正则表达式不知何故是错误的。

有人可以帮助我吗?

PS:我很确定GeoPointsRestController.php存在并且走在正确的道路上

您需要将正则表达式修复为^并且中间不匹配$

RewriteRule ^api/geopointsnearlocation/(-?(?:'d+|'d*'.'d+))/(-?(?:'d+|'d*'.'d+))/?$ api/GeoPointsRestController.php?lat=$1&lng=$2 [NC,QSA,L]