apache排除特定目录地址
根据这篇文章使用.htaccess实现目录跳转的代码,进一步的改进而来的,同事看到http://ip/a这个url地址之后,要求改成访问a目录,url地址就是http://ip,b目录是软链接在a目录中,还要求访问a目录是有apache身份认证的,而访问http://ip/b是没有身份认证的,下面就是我的解决方案.
系统:centos 5.5
环境:lamp环境
1.修改apache配置文件
vi /etc/httpd/conf/httpd.conf
NameVirtualHost 192.168.1.104:80
<VirtualHost 192.168.1.104:80>
ServerAdmin rocdk890@gmail.com
directoryIndex index.html index.php index.htm index.shtml login.php
ServerName 192.168.1.104
DocumentRoot /var/www/vhosts/wwwroot/a
<Directory "/var/www/vhosts/wwwroot/a">
Options -Indexes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
把这两项指向a目录
DocumentRoot /var/www/vhosts/wwwroot/a
<Directory "/var/www/vhosts/wwwroot/a">
保存后,重启apache.
service httpd restart
2.去a目录下添加修改.htaccess文件
vi /var/www/vhosts/wwwroot/a/.htaccess
AuthUserFile /var/www/vhosts/wwwroot/.htpasswd
AuthName "Please Enter Your Password"
AuthType Basic
Require valid-user
3.去b目录下添加修改.htaccess文件
vi /var/www/vhosts/wwwroot/b/.htaccess
Satisfy Any
Order Deny,Allow
Allow from all
这样就可以让b目录不被身份认证限制住.
好了,大家可以看到访问http://ip是有apache身份认证的,访问http://ip/b是没有apache身份认证的.
系统:centos 5.5
环境:lamp环境
1.修改apache配置文件
vi /etc/httpd/conf/httpd.conf
NameVirtualHost 192.168.1.104:80
<VirtualHost 192.168.1.104:80>
ServerAdmin rocdk890@gmail.com
directoryIndex index.html index.php index.htm index.shtml login.php
ServerName 192.168.1.104
DocumentRoot /var/www/vhosts/wwwroot/a
<Directory "/var/www/vhosts/wwwroot/a">
Options -Indexes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
把这两项指向a目录
DocumentRoot /var/www/vhosts/wwwroot/a
<Directory "/var/www/vhosts/wwwroot/a">
保存后,重启apache.
service httpd restart
2.去a目录下添加修改.htaccess文件
vi /var/www/vhosts/wwwroot/a/.htaccess
AuthUserFile /var/www/vhosts/wwwroot/.htpasswd
AuthName "Please Enter Your Password"
AuthType Basic
Require valid-user
3.去b目录下添加修改.htaccess文件
vi /var/www/vhosts/wwwroot/b/.htaccess
Satisfy Any
Order Deny,Allow
Allow from all
这样就可以让b目录不被身份认证限制住.
4.软链b目录到a目录中
ln -s /var/www/vhosts/wwwroot/b/ /var/www/vhosts/wwwroot/a/b
好了,大家可以看到访问http://ip是有apache身份认证的,访问http://ip/b是没有apache身份认证的.
评论: