1. To make the. htaccess valid, you need to do httpd.conf setup first
#打开改写模式
Options followsymlinks allowoverride All
#打开重写模式, remove this line of comment
LoadModule Rewrite_module modules/mod_rewrite.so
2..htaccess File Settings:
(1) Error file location:
Common client Pleading Error return code: (see http://www.cnblogs.com/boystar/p/4661106.html)
Format:errordocument error code/directory name/name. Extension
#例子:
ErrorDocument 404/errors/404.html
#如果提示很少的话, you can also output errors directly in the instruction
ErrorDocument 401 "You have permission to access this page, please give up!" "
(2) File access password protection:
Password protection is achieved by establishing a. htpasswd file,
① First Use the apache/bin/htpasswd file to set the. htpasswd Password
#在命令行中运行
#生成的 the contents of the. htpasswd file are:
Username: ciphertext Password
② setting up a. htpasswd file after you set up the. htaccess file
#例子:
AuthUserFile c:/www/data/.htpasswd #加密文件的目录
authgroupfile/dev/null #授权访问的目录
#可定义
AuthType Basic #授权类型, you can use the default
#设置可以访问的用户, this is all users
#require设置有3种:
#require any one user in the Valid-user password file
#require user Username1[username2[username3.]] Specify user
#require group groupname specified user groups
③ Setting IP Access restrictions
#例子
Order allow,deny #生效规则, 210.10.56.32 #禁止某IP访问 219.5.45 is forbidden after the first permission. #禁止某IP段访问 #除上述外, allow all
(3) URL Steering:
Format: Redirect/old directory/old document name New document Directory/new document name
#例子
Redirect old/old_name new/new_name #转移文档
Redirect old/new/ #转移文档目录
(4) Set default homepage:
Format: DirectoryIndex default home Name
# Example DirectoryIndex index.php index.html index.htm
(5) Prevent hotlinking
#例子
Rewriteengine on #打开重写引擎rewritecond %{http_referer}!^$ #空链接 !^http://(ww W.)? mydomain.com/.*$ [NC] #保护链接 #设置替代图片
(6) Setting pseudo-static
#例子
<module mod_rewrite.c> #如果打开重写模式 rewriteengine on #打开重写引擎 #设置根目录 ^test_ (. *). html$ test.php?id=$1 [L] #设置test. php?id=1 into test_1.html</ ifmodule> #结束
. htaccess File Settings