我的根目录中有一个自定义404错误页面。
我也编辑了.httaccess文件。
现在,如果某些情况在我的页面中失败,我想重定向到我的自定义404页面。
例如,$ _SESSION [log] == 1失败。
所以我的问题是
1.我应该在php中使用什么代码呢?
2.如何制作其他类型的错误,例如401和许多其他类型的错误?
在我的.httaccess页面中,这些行
ErrorDocument 404 http://mydomain.com/404custom.php
我有一个404custom.php可以满足我的需求。简单的HTML页面...
最佳答案
1-要重定向您的用户,您可以使用:
<?php
header('Location: http://www.example.com/404.html');
?>
但是在使用
header()
,echo
甚至空格之前,您不得发送任何数据。2-对于其他错误:
ErrorDocument 400 /var/www/errors/index.html
ErrorDocument 401 /var/www/errors/index.html
ErrorDocument 403 /var/www/errors/index.html
ErrorDocument 404 /var/www/errors/index.html
ErrorDocument 500 /var/www/errors/index.html
关于php - 重定向到我的custom404错误页面php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16196403/