且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在不更改请求URL的情况下重定向到HTTP错误文档

更新时间:2021-12-27 01:51:56

如果是4xx状态,你可以只显示错误html的内容码。否则重定向:

You can just display the contents of the error html in case of an 4xx status code. Otherwise redirect:

public static function Redirect($url, $code = '303 See Other') {
    header('HTTP/1.1 ' . $code);
    if(strpos($code, '4') === FALSE) {
        header('Location: ' . $url);
    } else {
        include(get_error_page_file_name($code));
    }
    exit(0);

}

以上示例将发送正确的HTTP状态代码,将显示错误页面的内容,并使您的网址在地址中保持不变。

The above example will send proper HTTP status code, will display the contents of the error page and keeps your url in the address the same.