【问题标题】:Redirect banned IPs to 404 rather than 403将禁止的 IP 重定向到 404 而不是 403
【发布时间】:2011-10-10 11:05:02
【问题描述】:

我有一个目录,我只想在我的办公室内访问。我有这个工作,并阻止就好了。这是我的 apache conf 中的内容:

<Directory /var/www/html/live/protected>
  Order deny,allow
  allow from 1.1.1.1.1.1 # My office ip
  deny from all
</Directory>

与其创建自定义 403 页面,我更愿意将这些人发送到 404 页面。在 Apache 中有没有一种方法可以有条件,如果它们不是来自我的办公室 IP,我可以将它们发送到我拥有的 404 页面?

谢谢

【问题讨论】:

标签: apache redirect http-status-code-403


【解决方案1】:

【讨论】:

  • 谢谢,但这两个我都看过。我希望仅根据 IP 有条件地执行此操作。看看我的示例配置。我不想仅仅基于目录,而是基于IP。有意义吗?
【解决方案2】:

要将所有 403,400 错误更改为 404 错误,请将其放在 /etc/apache2/conf.d/localized-error-pages 的末尾或放入 .htaccess 或者进入你的&lt;Directory /usr/share/phpmyadmin&gt;

# Will raise a 404 error, because the file <fake_file_for_apache_404.php> doesn't exist.
# We change 403 or 400 to 404 !
ErrorDocument 400 /fake_file_for_apache_404.php
ErrorDocument 403 /fake_file_for_apache_404.php
# We need to rewrite 404 error, else we will have "fake_file_for_apache_404.php not found"
ErrorDocument 404 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL <script type=\"text/javascript\">document.write(document.location.pathname);</script> was not found on this server.</p></body></html>"
ErrorDocument 500 "Server in update. Please comme back later."

【讨论】:

    猜你喜欢
    • 2020-05-30
    • 2019-07-29
    • 2021-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 2014-05-02
    • 2014-12-01
    • 1970-01-01
    相关资源
    最近更新 更多