From da631ff924d136a12d60bd57cbed12750b347c89 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Sat, 12 Jul 2025 17:17:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20=E4=BF=AE=E5=A4=8D=E7=A9=BAaction?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=A4=84=E7=90=86=E5=B9=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BC=AA=E9=9D=99=E6=80=81=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复当action参数为空时API根路径的错误处理 添加.htaccess伪静态规则以支持更友好的API URL --- .htaccess | 8 +++++++- api.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.htaccess b/.htaccess index fdb01af..5e2f2ac 100644 --- a/.htaccess +++ b/.htaccess @@ -3,4 +3,10 @@ LimitRequestBody 524288000 # 错误处理 ErrorDocument 500 /error_pages/500.html -ErrorDocument 404 /error_pages/404.html \ No newline at end of file +ErrorDocument 404 /error_pages/404.html + +# API 伪静态规则 +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^api(/.*)?$ api.php?action=$1 [QSA,L] \ No newline at end of file diff --git a/api.php b/api.php index 4322053..353d3a5 100644 --- a/api.php +++ b/api.php @@ -6,7 +6,7 @@ header('Content-Type: application/json'); $requestMethod = $_SERVER['REQUEST_METHOD']; // API根路径处理 - 返回可用端点信息 -if (!isset($_GET['action'])) { +if (!isset($_GET['action']) || $_GET['action'] === '') { http_response_code(200); echo json_encode([ 'status' => 'success',