. htaccess ErrorDocument How to use

Source: Internet
Author: User
Tags response code

The Web server does not respond to the user's needs and generates various error messages, all of which have a code, and we'll look at what this code means:


Response Code
Response Content
representative meaning
401
Authorization failed
authorization failed. User-entered account password cannot be authorized.
403
Forbidden
The access control mechanism rejects the user's request, which means you cannot read the file.
404
File not found
The requested webpage does not exist on this server and cannot find the file.
-
Internal Server Error
Server Internal error, there may be a problem with the Web server or PHP.
501
Not implemented
the server does not understand how data is passed.
503
Service unavailable
This server is currently dealing with too many service requirements.

"Figure 1 How to display a file when not found"

What if we want to customize the error message? To set the error page, enter it in the. htaccess:
ErrorDocument error code/folder/file name at the beginning of the site root directory

For example, if the user cannot find the page, it will produce a 404 error callback, please add the following data in the. htaccess:
ErrorDocument 404/error/notfound.htm automatically turns to localhost (or your website's IP)/error/notfound.htm when the user browses to a nonexistent page,


Figure 2 Customizing what is displayed when the profile is not found

So you can add multiple lines of syntax to the. htaccess for the above error scenarios:
ErrorDocument 401/errors/authreqd.html
ErrorDocument 403/errors/forbid.html
ErrorDocument 404/errors/notfound.html
ErrorDocument 500/errors/serverr.html

In addition to the page in the directory, you can point to a URL, you can share the same error message multiple sites, and then to find the page, there will be a 404 error callback, you can add the following data within the. htaccess:

ErrorDocument 404 http://localhost/error/notfound.htm ErrorDocument can also be followed by a paragraph of text or directly specify a section of HTML syntax, but, Text or HTML must be the same line as ErrorDocument. When you can't find the page, you want to display the text, and you can add the following data to the. htaccess:

ErrorDocument 404 "page Not found!!" when the page is not found, you want to display the Web page, you can add the following data in. htaccess:

ErrorDocument 404 "

Figure 3 Customizing what is displayed when the profile is not found

In addition: If the problem is due to the absolute path and relative path.
It is best to add an Alias in front to define the path of the/error/, otherwise the file may not be found because of a path error.

alias/errors/"/var/www/web4/web/error/"

errordocument 401/errors/error.html

. htaccess ErrorDocument How to use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.