In this article, we'll look at how you can use the .htaccess file to set up custom error pages. We will also give an example of how to set up permanent redirection for an entire site or a specific page.
Dealing with web server errors
Sometimes there are situations when an error occurs when loading a site or accessing a resource. The .htaccess file provides the ability to display a custom error page for the site visitor instead of a standard error code. This will provide the site visitor with a simpler explanation of the error that occurred.
The most common errors are 403 and 404, so they usually create their own notification pages for them. Also provide exit paths from this page.
This directive is set as follows:
ErrorDocument 404 http://domain-name.com/errors/404.html
In this case, the URL - http://domain-name.com/errors/ - is a link to the page that should be displayed in case of a corresponding error.
Setting up a 301 redirect
One of the tools for setting up persistent redirects is the .htaccess file directives. They are set as follows:
- redirecting the entire site to a different domain name:
Redirect 301 / http://www.new-website.com/
- redirecting a specific page to a new one:
Redirect 301 /page1.html http://new-website.com/page1.html
What is the .htaccess file for you can find out in the article by the link.