public static function appRedirect($url, $permanent = false) { $current_url = self::$url->getAddressElements(); $path_info = self::$url->getPath(); $path = ''; foreach ($current_url as $element) { $path .= $element; } $url = Helper::stringFilter($url); $url = str_replace('http://', '', $url); $url = str_replace('www.', '', $url); $url = str_replace($_SERVER['SERVER_NAME'], '', $url); $redirect_path = str_replace($path_info, '', $path); $redirect_path = str_replace('?', '', $redirect_path); $redirect_path = str_replace($_SERVER['QUERY_STRING'], '', $redirect_path); $redirect_path = 'http://' . $redirect_path . $url; $current_path = 'http://' . $path; if ($redirect_path != $current_path) { header('Location: ' . $redirect_path, true, true === $permanent ? 301 : 302); } }