From 0de6ec510a87d7f7bedee7d5f494ddd398a79103 Mon Sep 17 00:00:00 2001 From: printempw Date: Fri, 22 Jul 2016 08:55:41 +0800 Subject: [PATCH] abandon support of subdir --- app/Services/Http.php | 21 +++++++++++++++++++++ index.php | 13 +++++++++++-- resources/views/index.tpl | 18 +++++++++--------- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/app/Services/Http.php b/app/Services/Http.php index de7f6bd5..f37d3e75 100644 --- a/app/Services/Http.php +++ b/app/Services/Http.php @@ -33,6 +33,27 @@ class Http return $ip; } + public static function setUri($uri) + { + $_SERVER["REQUEST_URI"] = $uri; + return true; + } + + public static function getUri() + { + return $_SERVER["REQUEST_URI"]; + } + + public static function getCurrentUrl() + { + $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? "https://" : "http://"; + $url .= $_SERVER["SERVER_NAME"]; + $url .= ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); + $url .= $_SERVER["REQUEST_URI"]; + + return $url; + } + public static function abort($code, $msg = "Something happened.", $is_json = false) { http_response_code((int)$code); diff --git a/index.php b/index.php index 79e6ec3e..1ce2a111 100755 --- a/index.php +++ b/index.php @@ -30,6 +30,16 @@ foreach ($services as $facade => $class) { class_alias($class, $facade); } +/** + * URL ends with slash will cause many reference problems + */ +if (\Http::getUri() != "/" && substr(\Http::getUri(), -1) == "/") +{ + die(\Http::getUri()); + $url = substr(\Http::getCurrentUrl(), 0, -1); + \Http::redirect($url); +} + // Check database config $db_config = require BASE_DIR.'/config/database.php'; \Database::checkConfig($db_config); @@ -42,8 +52,7 @@ $capsule->bootEloquent(); session_start(); \Pecee\SimpleRouter\SimpleRouter::group([ - 'exceptionHandler' => 'App\Exceptions\RouterExceptionHandler', - 'middleware' => 'App\Middlewares\RemoveUrlSlashMiddleware' + 'exceptionHandler' => 'App\Exceptions\RouterExceptionHandler' ], function() { require BASE_DIR.'/config/routes.php'; }); diff --git a/resources/views/index.tpl b/resources/views/index.tpl index 7c50f1f4..95917095 100644 --- a/resources/views/index.tpl +++ b/resources/views/index.tpl @@ -4,15 +4,15 @@ {{ Option::get('site_name') }} - + - + - + - + @@ -32,7 +32,7 @@ @@ -44,20 +44,20 @@ - User Image + User Image