例:
<VirtualHost *:80>
DocumentRoot /opt/www/demo.test.com/
ServerName demo.test.com
<Directory "/opt/www/demo.test.com/">
Options FollowSymLinks
AllowOverride all
Order allow,deny
Allow from 127.0.0.1
</Directory>
</VirtualHost>
1、AllowOverride all 允许访问web目录下的.htaccess文件
2、Order allow,deny 控制deny和allow的优先级(在后面的优先级高于前面的)
allow在前,deny from 未设置,则没有允许的就是拒绝
deny在前,allow from未设置,则没有拒绝的都是允许
3、如果有.htaccess文件存在,并且allowoverride选项是all,则在.htaccess文件里设置的deny或allow会覆盖配置文件里的设置
在.thaccess文件里如果没有加"order deny,allow" 则默认使用“order deny,allow”(即deny在前,allow在后,allow权限优先于deny)
例:1、只允许本地访问
<Directory "/opt/www/demo.test.com/">
Options FollowSymLinks
AllowOverride all
Order allow,deny
Allow from 127.0.0.1
deny from all #(此行可加可不加)
</Directory>
2、禁止192.168.1.1访问
<Directory "/opt/www/demo.test.com/">
Options FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
Deny from 192.168.1.1
</Directory>
原文:http://www.cnblogs.com/xuxyblog/p/4335222.html