Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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

  • If the request comes from my IP 1.2.3.4, 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?

share|improve this question

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.

share|improve this answer
    
"Best way is not from .conf file" - Providing the criteria are fixed then it is more efficient to do this in httpd.conf –  w3d Mar 22 at 11:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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