DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Chara has posted 50 posts at DZone. View Full User Profile

Custom Error Pages in .htaccess

08.18.2013
| 4375 views |
  • submit to reddit
This example shows you how to define custom error pages in .htaccess file and also how to display the error page on your site. 

 

# Sample 1: redirect errors to html files
ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 405 /405.html
ErrorDocument 408 /408.html
ErrorDocument 414 /414.html
ErrorDocument 500 /500.html
ErrorDocument 502 /502.html
ErrorDocument 504 /504.html
 
# Sample 2: redirect errors to PHP file
ErrorDocument 400 /error.php?q=400
ErrorDocument 401 /error.php?q=401
ErrorDocument 403 /error.php?q=403
ErrorDocument 404 /error.php?q=404
ErrorDocument 405 /error.php?q=405
ErrorDocument 408 /error.php?q=408
ErrorDocument 414 /error.php?q=414
ErrorDocument 500 /error.php?q=500
ErrorDocument 502 /error.php?q=502
ErrorDocument 504 /error.php?q=504