From 148b0b83e490691dbea87a18a713b63b72f321f9 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 12 Jun 2013 19:27:45 +0200 Subject: [PATCH] Forcing redirect to application's domain if mismatching --- .../system/request/RequestHandler.class.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index 2fb25bff34..8c729f1a09 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -7,6 +7,7 @@ use wcf\system\exception\SystemException; use wcf\system\menu\page\PageMenu; use wcf\system\SingletonFactory; use wcf\system\WCF; +use wcf\util\FileUtil; use wcf\util\HeaderUtil; use wcf\util\StringUtil; @@ -121,6 +122,27 @@ class RequestHandler extends SingletonFactory { } } + // check if accessing from the wrong domain (e.g. "www." omitted but domain was configured with) + $applicationObject = ApplicationHandler::getInstance()->getApplication($application); + if ($applicationObject->domainName != $_SERVER['HTTP_HOST']) { + // build URL, e.g. http://example.net/forum/ + $url = FileUtil::addTrailingSlash(RouteHandler::getProtocol() . $applicationObject->domainName . RouteHandler::getPath()); + + // add path info, e.g. index.php/Board/2/ + $pathInfo = RouteHandler::getPathInfo(); + if (!empty($pathInfo)) { + $url .= 'index.php' . $pathInfo; + } + + // query string, e.g. ?foo=bar + if (!empty($_SERVER['QUERY_STRING'])) { + $url .= '?' . $_SERVER['QUERY_STRING']; + } + + HeaderUtil::redirect($url, true); + exit; + } + $controller = $routeData['controller']; // validate class name -- 2.20.1