Add Context::redirect() method

This commit is contained in:
Kijin Sung 2024-05-27 01:47:29 +09:00
parent 8a012a5847
commit 4c47793828

View file

@ -252,9 +252,8 @@ class Context
// Redirect to SSL if the current domain requires SSL.
if (!RX_SSL && PHP_SAPI !== 'cli' && $site_module_info->security !== 'none' && !$site_module_info->is_default_replaced)
{
$ssl_url = self::getDefaultUrl($site_module_info, true) . RX_REQUEST_URL;
self::setCacheControl(0);
header('Location: ' . $ssl_url, true, 301);
$url = self::getDefaultUrl($site_module_info, true) . RX_REQUEST_URL;
self::redirect($url, 301);
exit;
}
@ -502,6 +501,20 @@ class Context
}
}
/**
* Redirect
*
* @param string $url
* @param int $status_code
* @param int $ttl
* @return void
*/
public static function redirect(string $url, int $status_code = 302, int $ttl = 0): void
{
header("Location: $url", true, $status_code);
self::setCacheControl($ttl);
}
/**
* Load the database information
*