/ Published in: PHP
This example shows you how to define custom error pages in .htaccess file and also how to display the error page on your site. You may create separate files for each error, described in Sample 1 or just create the one PHP file for Sample 2. Here the PHP template for dealing with any sort of error, if you want to keep it simple:
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# 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 <?php // @file error.php ); $error_msg = $status[$_GET["q"]]; } foreach ($error_msg as $err) echo $err."<br>"; }else{ echo "Something went wrong."; } ?>
URL: http://www.apphp.com/index.php?snippet=htaccess-custom-error-pages