. Htaccess usage Summary

Source: Internet
Author: User
Article Title:. htaccess usage summary. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Unix, Linux, or any version of Apache Web Services Support. htaccess, but some host service providers may not allow you to customize your. htaccess file. Almost all mainstream VM providers abroad support custom functions.

To enable. htaccess, you must modify httpd. conf, enable AllowOverride, and use AllowOverride to restrict the use of specific commands.

If you want to use a file name other than. htaccess, you can use the AccessFileName command to change the file name. For example, to use. config, you can configure it in the server configuration file as follows:

AccessFileName. config

In general ,. htaccess can help us achieve the following: folder password protection, automatic user redirection, custom error pages, users who change your file extension, ban specific IP addresses, users who only allow specific IP addresses, and list of prohibited directories, and use other files as index files.

● Create a. htaccess document

. Htaccess is a weird file name (from Win's point of view, it has no file name and only has an extension consisting of eight letters, but it is actually named in linux, in many linux systems, we always think it is odd.) In Win systems, we cannot directly create new files, however, we can use copy in cmd, such as copy sample.txt. htaccess. You can also create an htaccess.txt file, Ftp it to the server, and modify the file name through FTP.

● Custom error page

. One application of htaccess is a custom error page, which enables you to have your own personalized error page (for example, when a file cannot be found ), instead of the error pages provided by your service provider or without any pages. This will make your website look more professional when an error occurs. You can also use the script program to notify you when an error occurs (for example, automatically Email you when the page cannot be found ).

You can add the following text to the. htaccess file to convert any page error code you know (such as page 404 cannot be found) to a custom page:

ErrorDocument errornumber/file.html

For example, if my root directory contains a notfound.html file, I want to use it as the 404 error page:

ErrorDocument 404/notfound.html

If the file is not in the root directory of the Website, you only need to set the path:

ErrorDocument 500/errorpages/500.html

The following are some of the most common errors:

401? Authorization Required needs to be verified

400? Bad request error request

403? Forbidden

500? Internal Server Error

404? Wrong page cannot find the page

Next, you only need to create a file displayed when an error occurs, and then upload them together with. htaccess.

●. Htaccess command

? Disable directory list display

Sometimes, for some reason, there is no index file in your directory, which means that when someone typed the directory path in the address bar of the browser, all the files in the directory will be displayed, this will leave security risks to your website.

To avoid this situation (instead of creating a bunch of new index files), you can type the following command in your. htaccess document to prevent

Display the directory list:

Options-Indexes

? Block/allow specific IP addresses

In some cases, you may only want to allow users of certain IP addresses to access your website (for example, only users of specific ISPs can access a directory ), or you want to block some specific IP addresses (for example, isolate low-level users from outside your information layout ). Of course, this is only useful when you know the IP address you want to intercept. However, most users on the Internet use dynamic IP addresses, so this is not a common method to restrict the use of dynamic IP addresses.

You can use the following command to block an IP Address:

Deny from 000.000.000.000

Here, 000.000.000.000 is the banned IP address. If you specify only a few of them, you can block the IP address of the entire network segment. If you enter 210.10.56., 210.10.56.0 ~ All IP addresses of 210.10.56.255.

You can use the following command to allow an IP address to access a website:

Allow from 000.000.000.000

The allowed IP address is 000.000.000.000. You can allow the entire network segment like the banned IP address.

If you want to prevent everyone from accessing this directory, you can use:

Deny from all

However, this does not affect the use of the files in this directory by the script program.

[1] [2] Next page

Related Article

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.