【发布时间】:2026-01-27 12:40:01
【问题描述】:
我正在创建一个 rest api 端点来将数据输入数据库。我一直在尝试将 url 重写为这种格式http://example.com/src/public/endpoint/data。 url 中的 public 是一个文件夹,其中有一个 index.php 文件,所有 url 都将被路由到该文件,但它不起作用。下面是我的 .htaccess 代码。
RewriteEngine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://example.com/src/public/index.php?path=$1 [NC,L,QSA]
当我期望example.com/src/public/state/127 时,我将链接地址http://example.com/src/public/?path=state/127&_=1579497796272 作为端点。我知道我做的不对,但我想不通。
【问题讨论】:
-
什么不起作用?您输入的是什么地址,似乎提取了哪个地址?一般而言,URL 重写的想法是将“好的”URL(
RewriteRule的第一部分)重写为“真实的”URL(第二部分),而不是相反。
标签: php rest .htaccess endpoint