2015-10-18 134 views
0

我试图返回IIS-8中的默认404错误页面。我使用此代码:包含404错误页面

// Return 404 in case no product was found 
if($product_index == -1) { 
    header('HTTP/1.0 404 Not Found'); 
    exit; 
} 

这段代码有404错误响应,但页面只是空白。
有没有办法使用PHP包含默认的404错误页面?

+0

您可以添加一个'location'到转到404页面:'header('Location:404.html');' –

+0

是的,这可以工作,但我想保持用户在同一页面(而不是重定向,我会使用include)。如何获取404错误页面文件路径? – Tompina

+0

不清楚你在说什么?如果用户打开根本不存在的页面,则他必须仅发送到404页面。 –

回答

0

简单地重定向到404页,像下面再次添加标题:

// Return 404 in case no product was found 
if($product_index == -1) { 
    header('HTTP/1.0 404 Not Found'); 
    header("Location: http://yoursite/404.php"); 
    exit; 
} 

如果你还碰到麻烦,由于IIS-8,那么你就可以按照Custom 404 error page not working on IIS 8.5