php - 使用PHP和htaccess处理错误页面

标签 php .htaccess error-handling

我想在我的htaccess文件中输入如下代码:

ErrorDocument 403 /error/403
ErrorDocument 404 /error/404
ErrorDocument 500 /error/500
...

并有一个PHP文件,该文件使用GET为我处理错误页面(file.php?a = 404)。

现在,我只需要htaccess代码即可将“/error/404”重写为“file.php?a = 404”。我该怎么办 ?!

最佳答案

您可能还希望自定义其他一些错误文档。
400-错误的要求
401-需要授权
403-禁止目录
404页面不存在
500内部服务器错误

对于您要使用的每个文件,只需在.htaccess文件中添加一行,然后创建相应的页面。

ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html

关于php - 使用PHP和htaccess处理错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16662355/

相关文章:

javascript - 如何在 Vuejs 中使用 Laravel Blade 语法

apache - 两个域及其子域映射到同一个 IP,那么我如何将不同的应用程序托管到同一个 tomcat 服务器?

php - 简单的子域重定向 PHP

python - 我的代码如何在 Python 中只接受整数?

php - 使用ajax删除选中的表行

php - 如何选择更多条件的用户

javascript - 调整大小时如何修复页脚重叠内容

php - 优化 mod_rewrite

android - Android-日志中出现IOException错误

swift - 在 Swift 中的观察者方法中抛出错误