1. How to get your own local Apache server support. htaccess
How do I get my local Apache server to support ". htaccess"? In fact, simply modify the Apache httpd.conf settings to allow Apache support. htaccess, take a look at the operation.
Open the httpd.conf file (where?) Apache directory, with a text editor open, find
(1)
Options FollowSymLinks
AllowOverride None
To
Options FollowSymLinks
AllowOverride All
(2) Remove the following note
LoadModule Rewrite_module modules/mod_rewrite.so
It's okay.
2. htaccess
The directory where the #.htaccess file resides
rewritebase/#目录名字
Rewriteengine on #打开引擎
Rewriterule #匹配规则 #跳转路径
The. htaccess file (or distributed configuration file) in the Apache system provides a way to configure changes to the directory, that is, to place a file containing one or more directives in a specific document directory to function in this directory and all its subdirectories. As a user, the commands you can use are limited. The administrator can set it through the Apache allowoverride directive.
The directives in the subdirectory overwrite the instructions in the higher-level directory or the primary server configuration file.
. htaccess must be uploaded in ASCII mode, preferably with the permissions set to 644.
Locating the wrong document
Common Client Request error return code:
401 Authorization Required
403 Forbidden
404 Not Found
405 Method Not allowed
408 Request Timed out
411 Content Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type
Common Server error return code:
Internal Server Error
Users can use. htaccess to specify their own prepared Error alert page. In general, people can set up a directory specifically, such as errors to place these pages. And then again. htaccess, add the following instructions:
ErrorDocument 404/errors/notfound.html
ErrorDocument 500/errors/internalerror.html
A single line of instructions. The first instruction above means that the page is displayed as a notfound.html page in the/errors directory for 404, which is when the required document is not found. It is not difficult to see that the syntax format is:
ErrorDocument error code/directory name/filename. extension
If you need to be prompted with very little information, you don't have to create a page to use the HTML number directly in the instruction, such as the following example:
ErrorDocument 401 "You do not have access to this page, please give up!" ”
Password protection for document access
To use. htaccess to set access to the user and corresponding password for a document in a directory, the first thing to do is to generate a. htpasswd text document, such as:
Zheng:y4e7ep8e7eyv
The password is encrypted, and the user can find some tools to encrypt the password into a. htaccess supported encoding. This document is best not to be placed in the WWW directory, it is recommended to be placed outside the WWW root document, which is more secure.
With the authorized user documentation, you can add the following directive to the. htaccess:
Server directory for AuthUserFile. htpasswd
Authgroupfile/dev/null (directories that require authorization to access)
AuthName Enterpassword
AuthType Basic (Authorization type)
Require user wsabstract (users who are allowed to access, you can use require valid-user if you want all users in the table to allow it)
Note, brackets part for the time of learning to add their own notes
Deny access from an IP
If I don't want a government department to access the content of my site, I can reject it by joining the department's IP in the. htaccess.
For example:
Order Allow,deny
Deny from 210.10.56.32
Deny from 219.5.45.
Allow from all
The second line rejects an IP, and the third line rejects an IP segment, which is 219.5.45.0~219.2.45.255
Want to reject everyone? With the Deny from all. Not only with IP, you can also use domain name to set.
Protect. htaccess Documents
When you use. htaccess to set the password protection for a directory, it contains the path to the password file. From a security point of view, it is necessary to protect the htaccess, and not let others see the content. Although this can be done in other ways, such as the permissions of the document. However, htaccess itself can do so by simply adding the following instructions:
Order Allow,deny
Deny from all
URL Steering
We may be planning the site, migrating the document, or changing the directory. At this point, access from the search engine or other web links may be wrong. In this case, the old URL can be automatically shifted to the new address by using the following instructions:
Redirect/old directory/old document name new document address
or the entire directory of the steering:
Redirect Old Directory New directory
Change the default home file
Under normal circumstances, the default home page name has default, index and so on. However, there are times when there are no default files in the directory, but a specific file name, such as pmwiki.php in PmWiki. In this case, it is troublesome for the user to remember the filename to access. You can easily set a new default filename in. htaccess:
DirectoryIndex the new default filename
You can also list multiple, sequentially indicating the priority level between them, for example:
DirectoryIndex filename.html index.cgi index.pl default.htm
Prevent hotlinking
If you do not like others to connect their own pictures and documents on their Web pages, you can also do so by htaccess instructions.
The required directives are as follows:
Rewriteengine on
Rewritecond%{Http_referer}!^$
Rewritecond%{http_referer}!^http://(www.) mydomain.com/.*$ [NC]
Rewriterule. (gif&line;jpg) $–[f]
If you feel that letting someone else's page open a skylight doesn't look good, you can use a picture instead:
Rewriteengine on
Rewritecond%{Http_referer}!^$
Rewritecond%{http_referer}!^http://(www.) mydomain.com/.*$ [NC]
Rewriterule. (gif&line;jpg) $ http://www.mydomain.com/Alternative picture file name [r,l]
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.