I have a similar requirement and do basically the same when I put my page (or a part) on maintenance. The content of the htaccess file looks like this:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} /thisdirectoryandallcontents
RewriteCond %{REMOTE_ADDR} !=111.111.111.111
RewriteRule ^.*$ /maintenance.php [R=302,L]
I will explain it step by step according to your requirements:
- Every user should be able to access the homepage http://mydomain.com/ - cool, no configuration needed.
- The first RewriteCond checks, if the request lies within the folder /thisdirectoryandallcontents.
- The second RewriteCond checks, if the IP address is any other then 111.111.111.111 (here you have to write your IP address).
- If both of the conditions apply, we redirect the user to /maintenance.php. Here I usually output a message to the user, that the page is currently under maintenance. You could display a message, that the user doesn't have access to /thisdirectoryandallcontents.
Instead of redirecting the user to the maintenance page, you could also redirect him to the home page if you wish to.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…