简体   繁体   English

使用PHP和htaccess处理错误页面

[英]handle error pages using PHP and htaccess

I want put some codes like below in my htaccess file: 我想在我的htaccess文件中输入如下代码:

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

and have a PHP file which handles the error pages for me using GET ( file.php?a=404 ). 并有一个PHP文件,该文件使用GET为我处理错误页面(file.php?a = 404)。

Now, I only need a htaccess code to rewrite the "/error/404" to "file.php?a=404" for me. 现在,我只需要htaccess代码即可将“ / error / 404”重写为“ file.php?a = 404”。 What should I do ?! 我该怎么办 ?!

There's several other error documents that you might wish to customise. 您可能还希望自定义其他一些错误文档。 400 - Bad request 401 - Authorization Required 403 - Forbidden directory 404 - Page not found 500 - Internal Server Error 400-错误的请求401-需要授权403-禁止的目录404-找不到页面500-内部服务器错误

For each one you want to use, simply add a line to your .htaccess file and create the corresponding page. 对于您要使用的每个文件,只需在.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
ErrorDocument 404 /path/to/file.php?a=404
ErrorDocument 404 /path/to/yourfile.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM