After work today, colleagues asked about the use of this thing. I have not contacted before, specially search for a bit, now save convenient later use.
1. First determine the server type, whether the server is supported.
2. Whether there is an error in the wording.
3. Whether the required features are supported in. htaccess.
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 these functions are not
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
Allow from all
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 spaces are 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 picture Hot chain
The following. htaccess rule uses the 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.
According to my colleague sent me a message, she would like to achieve a pseudo-static part.
If Windows+iis, congratulations . Apache supports this. If IIS doesn't have an Apache module, you'll be blessed.