From 1a86fe8cbfd3645c981d19330dd6081c74eb1943 Mon Sep 17 00:00:00 2001 From: Crazy-White <565332016@qq.com> Date: Sun, 4 Oct 2020 22:41:00 +0800 Subject: [PATCH] Initial support for pseudo-static environment --- .htaccess | 12 ++++--- platform/Normal.php | 9 +++-- vendor/pathHandler/main.php | 67 +++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 vendor/pathHandler/main.php diff --git a/.htaccess b/.htaccess index 307e875..b978ded 100644 --- a/.htaccess +++ b/.htaccess @@ -2,16 +2,20 @@ # # LoadModule rewrite_module modules/mod_rewrite.so # # AllowOverride All RewriteEngine On -# RewriteCond $1 !^(.well-known) -RewriteRule ^(.*) index.php?/$1 [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*) index.php/$1 [L] ###----------------------------------- ### nginx -# rewrite ^/(?!.well-known)(.*)$ /index.php?/$1 last; +# +# if (!-e $request_filename) { +# rewrite ^(.*)$ /index.php/$1 last; +# } # ### caddy # rewrite { -# to index.php?/$1 +# to index.php/$1 # } # ### caddy2 Caddyfile diff --git a/platform/Normal.php b/platform/Normal.php index a261705..17207e7 100644 --- a/platform/Normal.php +++ b/platform/Normal.php @@ -1,16 +1,15 @@ 0) $path = substr($_SERVER['REQUEST_URI'], 0, $p); - else $path = $_SERVER['REQUEST_URI']; - $path = path_format( substr($path, strlen($_SERVER['base_path'])) ); - return $path; + return \pathHandler\get(0); //return substr($path, 1); //return spurlencode($path, '/'); } diff --git a/vendor/pathHandler/main.php b/vendor/pathHandler/main.php new file mode 100644 index 0000000..a86cffd --- /dev/null +++ b/vendor/pathHandler/main.php @@ -0,0 +1,67 @@ + + * @copyright 2020 (c) CrazyWhite - pathHandler + * @license https://opensource.org/licenses/MIT - The MIT License (MIT) + * @link https://github.com/Crazy-White/unpkg-proxy/tree/master/lib/pathHandler + * @since 1.0.0 + */ + +namespace pathHandler; + +function redirect() +{ + /* + 'localhost/sn.php?/path/to/file?fakeQuery' + to + 'localhost/sn.php?/path/to/file&fakeQuery' + then $_GET works + */ + $uri = $_SERVER['REQUEST_URI']; + $query = $_SERVER['QUERY_STRING']; + if (strpos($query, '?') > 0) { + $fixed_query = str_replace('?', '&', $query); + header('Location: ' . str_replace($query, $fixed_query, $uri)); + die(); + } +} + +function get($is_include_query = false) +{ + $pi = $_SERVER['PATH_INFO']; + $uri = $_SERVER['REQUEST_URI']; + $query = $_SERVER['QUERY_STRING']; + + if (isset($pi) && strlen($pi) > 0) { + + if (!$is_include_query) + return $pi; + //$_pi = str_replace('/', '\/', $pi); + $sn = addcslashes($_SERVER['SCRIPT_NAME'], '/'); + if (preg_match("/{$sn}(.+)$/", $uri, $matches)) { + return $matches[1]; + } + + } + + if ($query[0] === '/') { + + if ($is_include_query) { + return $query; + } else { + + $p = strpos($query, '&'); + if (!$p) { + $p = strpos($query, '?'); + if(!$p) return $query; + } + return substr($query, 0, $p); + + } + + } + + return '/'; +} \ No newline at end of file