|
|
@@ -37,8 +37,22 @@ Middleware::register('auth', [new AuthMiddleware(), 'handle']);
|
|
|
Middleware::register('permission', [new PermissionMiddleware(), 'handle']);
|
|
|
|
|
|
try {
|
|
|
- // 解析请求路径(去 query,规范化尾部斜杠)
|
|
|
- $path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
|
|
|
+ // 解析请求路径(去 query)
|
|
|
+ $requestUri = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
|
|
|
+
|
|
|
+ // 部署前缀自动检测:支持子目录部署(如 http://host/glacier/xxx)。
|
|
|
+ // 根部署(DocumentRoot 直指 public)时前缀为空,行为不变。
|
|
|
+ $scriptName = str_replace('\\', '/', $_SERVER['SCRIPT_NAME'] ?? '/index.php');
|
|
|
+ $basePath = rtrim(str_replace('\\', '/', dirname($scriptName)), '/');
|
|
|
+ if ($basePath === '.' || $basePath === '/') {
|
|
|
+ $basePath = '';
|
|
|
+ }
|
|
|
+ if ($basePath !== '' && str_starts_with($requestUri, $basePath)) {
|
|
|
+ $requestUri = substr($requestUri, strlen($basePath)) ?: '/';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 规范化尾部斜杠
|
|
|
+ $path = $requestUri;
|
|
|
if (strlen($path) > 1) {
|
|
|
$path = rtrim($path, '/');
|
|
|
}
|