Initial support for pseudo-static environment
parent
c502a1b6ab
commit
1a86fe8cbf
12
.htaccess
12
.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
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
<?php
|
||||
|
||||
require_once("./vendor/pathHandler/main.php");
|
||||
\pathHandler\redirect();
|
||||
|
||||
function getpath()
|
||||
{
|
||||
$_SERVER['firstacceptlanguage'] = strtolower(splitfirst(splitfirst($_SERVER['HTTP_ACCEPT_LANGUAGE'],';')[0],',')[0]);
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
$_SERVER['base_path'] = path_format(substr($_SERVER['SCRIPT_NAME'], 0, -10) . '/');
|
||||
if (isset($_SERVER['UNENCODED_URL'])) $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];
|
||||
$p = strpos($_SERVER['REQUEST_URI'],'?');
|
||||
if ($p>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, '/');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/**
|
||||
* Then no difficulty in handling path.
|
||||
*
|
||||
* @author CrazyWhite <moe@mailo.com>
|
||||
* @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 '/';
|
||||
}
|
Loading…
Reference in New Issue