v1.1.1页面修复

This commit is contained in:
2026-05-07 12:46:32 +08:00
parent e40fe98b42
commit 80b71a973a
3 changed files with 62 additions and 6 deletions

40
public/router.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
/**
* PHP 内置开发服务器路由文件
*
* 用法php -S localhost:8080 -t public/ public/router.php
*
* Nginx 部署不需要此文件Nginx 有自己的 URL 重写规则。
*/
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
// API 路由 — 所有 /api/ 请求统一转发到 api.php
if (str_starts_with($uri, '/api/')) {
require __DIR__ . '/api.php';
return true;
}
// 静态资源CSS/JS/图片/字体/上传文件等)
if ($uri !== '/' && preg_match('/\.(css|js|png|jpg|jpeg|gif|ico|svg|woff2?|ttf|eot|webp|webm|mp4|pdf|zip)$/i', $uri)) {
$file = __DIR__ . $uri;
if (is_file($file)) {
return false; // 让 PHP 内置服务器直接返回静态文件
}
}
// 根路径
if ($uri === '/' || $uri === '') {
require __DIR__ . '/index.php';
return true;
}
// 已存在的 PHP 文件直接访问
$phpFile = __DIR__ . $uri;
if (is_file($phpFile) && str_ends_with($uri, '.php')) {
return false; // 让 PHP 内置服务器处理
}
// 其他请求回退到 index.php
require __DIR__ . '/index.php';
return true;