Redirect banned IPs to 404 rather than 403

耗尽温柔 提交于 2019-12-11 13:15:35

问题


I have a certain directory I only want accessible from within my office. I have this working, and blocked just fine. Here is what I have in my 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>

Rather than create a custom 403 page, I would rather just send these people to 404 pages. Is there a way in Apache I can have a conditional that if they are not coming from my office IP, I can just send them to the 404 page I have?

Thanks


回答1:


Maybe this can help:

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

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




回答2:


To change all 403,400 errors into 404 errors, put this at the end of /etc/apache2/conf.d/localized-error-pages OR into a .htaccess OR into your <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."


来源:https://stackoverflow.com/questions/7711871/redirect-banned-ips-to-404-rather-than-403

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!