将禁止的IP重定向到404而不是403

时间:2011-10-10 11:05:02

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

我有一个我只想在办公室内访问的目录。我有这个工作,并阻止就好了。以下是我在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>

我宁愿将这些人发送到404页面,而不是创建自定义403页面。在Apache有没有办法我可以有一个条件,如果他们不是来自我的办公室IP,我可以将它们发送到我有的404页面吗?

由于

2 个答案:

答案 0 :(得分:0)

也许这会有所帮助:

RedirectMatch 404 ".*\/\..*"

- &GT; Is there a way to force apache to return 404 instead of 403?
- &GT; Problem redirecting 403 Forbidden to 404 Not Found

答案 1 :(得分:0)

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

# 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."