简体   繁体   中英

handle error pages using PHP and htaccess

I want put some codes like below in my htaccess file:

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 ).

Now, I only need a htaccess code to rewrite the "/error/404" to "file.php?a=404" for me. 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

For each one you want to use, simply add a line to your .htaccess file and create the corresponding page.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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