target_domain = strtolower($target_domain); $this->redirect_domains = $redirect_domains; } public function __invoke(Request $request, Response $response, callable $next) { $current_domain = $request->SERVER['SERVER_NAME']; if (strtolower($current_domain != $this->target_domain)) { if (empty($this->redirect_domains) || in_array($current_domain, $this->redirect_domains)) { $redirect_url = 'https://' . $this->target_domain . $request->SERVER['REQUEST_URI']; return $response->redirect($redirect_url, $this->redirect_status); } } return $next($request, $response); } }