禁止浏览.htaccess文件

很多黑客会攻击和利用.htaccess做网站跳转,所以保护好.htaccess文件尤为重要。

在apache的httpd.conf的配置文件中 默认是已经设置了禁止对.htaccess的访问,截取相关配置文件如下:

# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>

我通过:http://localhost/test/.htaccess,在本地默认访问我的.htacess文件出现:

Forbidden

You don't have permission to access /test/.htaccess on this server.

当然当apache没设这样的配置或者自己没权限更改配置文件时,你也可以手动在更改自己本地的.htacess文件,添加如下代码:

<Files .htaccess>
order allow,deny
deny from all
</Files>

这样的效果和上面一样。

当把deny改成allow,代码改成如下:

<Files .htaccess>
order allow,deny
allow from all
</Files>

我们的.htacess文件即可以被访问,当然这样是比较危险的,我们本地只是做个测试。还是赶快把allow改成deny吧。

原文地址:https://www.cnblogs.com/psz1992/p/4444595.html