3

我正在使用 htaccess 技术阻止一些 IP 地址,这适用于我的所有页面,除了显示 Fedora Core 测试页面的站点/文档根目录。

我知道在根目录中找不到文档时会显示测试页面,因此我创建了多个文档并设置了目录索引,其中 index.php 是我的常规文档根文件。

注意我无权访问 /etc/httpd/conf.d/welcome.conf

下面是相关的htaccess代码:

DirectoryIndex index.php index.html 403.php

ErrorDocument 403 /403.php

order allow,deny
deny from 5.39.218
deny from 146.0.74
deny from 5.39.219
deny from 176.102.38
allow from all

<FilesMatch "(403.php|hero.jpg|index.html)$">
 order allow,deny
 allow from all
</FilesMatch>

有没有办法为网站根目录显示我的自定义 403 页面?

任何建议将不胜感激。

4

3 回答 3

2

试试这个代码:

DirectoryIndex index.php index.html 403.php

ErrorDocument 403 /403.php

order allow,deny
allow from all
deny from 5.39.218
deny from 146.0.74
deny from 5.39.219
deny from 176.102.38
Satisfy    any

<FilesMatch "^(|403\.php|hero\.jpg)$">
 order allow,deny
 allow from all
</FilesMatch>
于 2013-11-17T04:45:54.430 回答
0

寻求完整解决方案的人:

  • 必须将 FilesMatch "^.*$" 行添加到 ip 以阻止
  • 将 ^ 添加到 FilesMatch 的前面以获得允许的文件

完成代码:

DirectoryIndex index.php index.html 403.php

ErrorDocument 403 /403.php

<FilesMatch "^.*$">
  order allow,deny
  allow from all
  deny from 5.39.218
  deny from 146.0.74
  deny from 5.39.219
  deny from 176.102.38
</FilesMatch>

<FilesMatch "^(|403\.php|hero\.jpg)$">
  order allow,deny
  allow from all
</FilesMatch>
于 2013-11-17T08:32:26.460 回答
0

尝试禁用默认的 Apache CentOS 欢迎页面:

#
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL.  To disable the Welcome page, comment
# out all the lines below.
#
<LocationMatch "^/+$">
    Options -Indexes
    ErrorDocument 403 /error/noindex.html
</LocationMatch>

编辑文件/etc/httpd/conf.d/welcome.conf并评论所有内容。只需删除welcome.conf文件(或.conf.disabled例如重命名它)也应该可以解决问题。

然后,重新加载 apache 配置 ( service httpd restart),一切都应该按预期工作。

于 2014-05-09T10:58:53.623 回答