What is the. htaccess? htaccess few simple applications

Source: Internet
Author: User
Tags parent directory cpanel password protection

What is the. htaccess?

. Htaccess is called a distributed configuration file, which provides a way to change the configuration of a directory by placing a file containing one or more instructions in a particular document directory to act on this directory and all its subdirectories. and the directives in the subdirectories overwrite the higher-level directories or the directives in the master server configuration file. In general, if your virtual host is using a UNIX or Linux system, or any version of the Apache Web server, it is theoretically supported. htaccess.

How to build. htaccess?

It is difficult to create. htaccess files on the Windows (Plague-to-death) host that we use. Writing a file is easy, and you just need to write down the appropriate code in the text editor (for example, Notepad). The difficult thing is to save the file because. htaccess is a quirky file name, but it does not have a file name, only a 8-letter (htaccess) extension, which is an unacceptable file name on Windows systems. Therefore, there are 3 ways to do this.

Method One: Save the file when the document is saved to fame as ". htaccess" (including quotation marks) or htaccess.txt or 1.htaccess. Then upload it to the server, and then rename it directly using the FTP software.

Method Two: Save the file by selecting Save As, save type Select all files, and then enter the file name. htaccess, so ok O (∩_∩) o ....

Method Three: Build directly on your UNIX or Linux virtual host.

What is the. htaccess? htaccess is a file that is set up under various permissions rules for the system directory under the Apache HTTP Server installation software, which exists in the Linux operating system.   More common is the definition of the default home page name, 404 pages, 301 turn, and so on, there are more features such as pseudo-static, limit the picture outside the chain, limit the download, password protection, remove page ads, and so on, there are a lot of features are not listed. In fact, most of these functions can be set in the Cpanel Control Panel (the equivalent of the graphical interface of the. htaccess). But for the master, cpanel for htaccess to provide the function is too little point, manual editing is kingly. Compared to the domestic virtual host, the vast majority of this function is not the directory rules Generally we place the. htaccess file at the root of the Web site, control the directory and all subdirectories, and if placed in subdirectories, are affected by the. htaccess file in the parent directory.

To cite a few examples, the following sections cite Wikipedia.

Custom error page (direct copy)

ErrorDocument 404/error-pages/not-found.html errordocument 503/error-pages/service-unavailable.html

————————————————————————- IP Disable

Order Allow,deny deny from 123.45.67.8 deny from 123.123.7

Above can prohibit the IP address in the 123.45.67.8 and the IP address at the beginning of 123.123.7 for anyone. For example, 123.123.74.42 cannot be accessed. ————————————————————————- Change default home page

DirectoryIndex homepage.html

————————————————————————- Remove Page ads (all free space is not necessarily available)

Layoutignoreuri *.php Layoutignoreuri *.cgi layoutignoreuri *.htm layoutignoreuri *.html LayoutIgnoreURI *.txt

————————————————————————- page Jump

Redirect page1.html page2.html

If someone accesses http://www.example.com/page1.html, he will be redirected to the http://www.example.com/page2.html (with HTTP status code 302) ——————————————— —————————- Server Built-in SSI

AddType text/html. shtml AddHandler server-parsed. shtml Options Indexes followsymlinks includes

————————————————————————-prevent the. htaccess rule behind the image hot chain using mod rewrite. Special domain name

Rewriteengine on Rewritecond%{http_referer} ^http://([^/]+\.)? baddomain1\.com [Nc,or] Rewritecond%{http_referer} ^http://([^/]+\.)? baddomain2\.com [Nc,or] Rewritecond%{http_referer} ^http://([^/]+\.)? baddomain3\.com [NC] rewriterule \. (gif|jpg) $ http://www.example.com/hotlink.gif [r,l]

Non-special domain name

Rewriteengine on Rewritecond%{http_referer}!^$ rewritecond%{http_referer}!^http://(www\.)? example.com/.*$ [NC] rewriterule \. (gif|jpg) $ http://www.example.com/hotlink.gif [r,l]

Unless example.com has this image, the browser can see Hotlink.gif. Note: Hotlink hot chain protection uses the. htaccess relies on the client to send the correct "commit" value in an HTTP GET request. Like trying to use Windows Media Player to send a blank submission to the. htaccess to protect the movie file is not valid.

Prohibit. htaccess files from being viewed add the following code to your. htaccess file to prevent others from accessing your. htaccess file:

<files .htaccess> order Allow,deny deny from all </Files>

Most versions of this web site have errors, most versions lose <files .htaccess>, resulting in all files being blocked from access. If you use the wrong rules, all of your content will not be accessible.

Similarly, if you want to prohibit access to other files, you can replace them with other filenames.

What is the. htaccess? htaccess few simple applications

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.