namespace wcf\system\request;
+use Laminas\Diactoros\Response\RedirectResponse;
use Laminas\Diactoros\ServerRequestFactory;
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
use Psr\Http\Message\RequestInterface;
use wcf\system\exception\SystemException;
use wcf\system\SingletonFactory;
use wcf\system\WCF;
-use wcf\util\FileUtil;
use wcf\util\HeaderUtil;
/**
// check if accessing from the wrong domain (e.g. "www." omitted but domain was configured with)
$domainName = ApplicationHandler::getInstance()->getDomainName();
- if ($domainName !== $_SERVER['HTTP_HOST']) {
- // build URL, e.g. http://example.net/forum/
- $url = FileUtil::addTrailingSlash(
- RouteHandler::getProtocol() . $domainName . RouteHandler::getPath()
- );
-
- // query string, e.g. ?foo=bar
- if (!empty($_SERVER['QUERY_STRING'])) {
- $url .= '?' . $_SERVER['QUERY_STRING'];
- }
+ if ($domainName !== $psrRequest->getUri()->getHost()) {
+ $targetUrl = $psrRequest->getUri()->withHost($domainName);
- HeaderUtil::redirect($url, true, false);
-
- exit;
+ return new RedirectResponse(
+ $targetUrl,
+ 301
+ );
}
}