htaccess custom redirection of error pages

htaccess custom redirection of error pages.

Making the custom error pages makes the site seems much professional.

In order to show customized error pages we need to add the error number and related error pages in .htaccess file.

You can use custom error pages for any error as long as you know its number (like 404 for page not found) by adding the following to your .htaccess file:

The format of added error pages to the error number is below :
ErrorDocument errornumber /file.html

For example if the error code is 401 which is page not found error add the below line in the .htaccess page to show the custom error page (notfound.html). Add the file notfound.html in the root directory of the site.

ErrorDocument 404 /notfound.html

If the error page is not in the root directory of your site, you can enter the path to the file:

ErrorDocument 404 /path_to_custom_error_page.html
like
ErrorDocument 404 /errorpages/notfound.html

These are some of the most common errors:
401 – Authorization Required
400 – Bad request
403 – Forbidden
500 – Internal Server Error
404 – Wrong page

Some examples for other errors

ErrorDocument 401/authorization-error-page

ErrorDocument 402/bad-request-error-page

ErrorDocument 403/forbidden-error-page

ErrorDocument 500/internal-server-error-page

 

You can read more about .htaccess by clicking here

Leave a Reply

Your email address will not be published. Required fields are marked *