I am using Apache and want to modify my .conf file for a website such that:

  • If the request comes from my IP, just display the URL/page as requested
  • If the request is not from my IP and the directory does not exist, redirect to root
  • If the request is not from my IP and the directory is one I don't want to display to anyone (example.com/secret/, example.com/secret2/hidden.html, etc.), redirect to root

What is the best way to do this?

1 Answer 1


Best way to do this is not from your .conf file. Do this:

.htaccess example:

    RewriteEngine on
    RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.1 #Replace with IP address you wish to allow
    RewriteRule .* http://www.yourwebsite.com [R=301,L] #Replace webaddress with yours

Make this file in the directories you are trying to keep people out of.

Then make a custom 404 page that redirects to root for the non-existant directories.

  • "Best way is not from .conf file" - Providing the criteria are fixed then it is more efficient to do this in httpd.conf
    – MrWhite
    Mar 22, 2014 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.