What do I put in a HTACCESS file to stop people viewing my site?

not sure how to with htaccess and a quick google doesn't say either, but one method could be to stick everything in one folder down, named anything, and put a temp index file in root folder saying under construction, then when done move everything back out of the folder back to root folder.
 
Well, you can either allow by IP address, or you can have password authentication.

To allow by IP address:
Code:
Order Deny,Allow
Allow From YOUR_IP_ADDRESS
Deny From All

Or, to require a user name and password to be entered, put this in the .htaccess file:
Code:
AuthUserFile /path/to/password/file/.htpasswd
AuthName "Some text to be shown in the password box"
AuthType Basic

require user USER_NAME

... and this in a .htpasswd file (in the location specified in the .htaccess file):
Code:
USER_NAME:PASSWORD

Alternatively, if you have shell access to your server (and it's running Linux), you can use the htpasswd command to generate the .htpasswd file for you:
Code:
htpasswd -cb /path/to/file/.htpasswd USER_NAME PASSWORD
 
Last edited:
not sure how to with htaccess and a quick google doesn't say either, but one method could be to stick everything in one folder down, named anything, and put a temp index file in root folder saying under construction, then when done move everything back out of the folder back to root folder.
The problem is that what I'm setting up has way too many settings which are set by the location you install it too, so moving it would be a pain, as most of it would stop working. So ideally it would be a lot easier to install it exactly where I want it to be. So I think htaccess is the only way to do this.

Inquisitor : so in htpasswrd file I replace "USER_NAME:PASSWORD" with my own user/pass, eg "seek:seekpass"?
 
If you want to redirect, you'd probably be best off using mod_rewrite:
Code:
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^YOUR_IP_ADDRESS
RewriteRule ^.*$ redirection_target.html [R=302,L]

If you do this, you need to put an escape character (a backslash) before each dot in the IP address.

Alternatively, you could simply specify your own 403 error page to be displayed to user in the case a denial:

Code:
ErrorDocument 403 error_page.html
 
Last edited:
If I use the IP deny thing, can I also make it redirect people to somewhere else, so that I can explain why the site is not available?

yeah that was also a reason for suggesting what i suggested as then atleast they'd be able to get a message you decided, other then you are not allowed etc, but a solution to this problem has been presented anyway so i'll shut up.
 
I believe you just add another allow from xxx.xxx.xxx.xxx on a new line... Could be wrong though. :)

TrUz
 
Back
Top Bottom