: How to restrict access to my site using htaccess How to disallow access to site except me?
How to disallow access to site except me?
More posts by @Sherry384
4 Comments
Sorted by latest first Latest Oldest Best
I once came up with a solution I call .htaccess maintenance mode.
It uses mod_rewrite, restricts the site to your IP address, and redirects other people to another URL.
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^192.168.1.100
RewriteCond %{REQUEST_URI} !^/403.html$
RewriteRule ^(.*)$ site.com/403.html [R=307,L]
A little explanation:
The first line checks the IP address. The third one redirects the user to the 403.html page. Basically it would redirect all pages to 403.html, including 403.html - the second line prevents that so users can't go into an endless redirect loop.
For the sake of variety: if you have a static IP address you could block all IP addresses except yours:
order deny, allow
deny from all
allow from xxx.xxx.xxx.xxx
Just change xxx.xxx.xxx.xxx to be your IP address.
(on Apache Server)
Steps
Choose the directory you wish to protect You wish to protect the whole site then chose "public_html". Also chose a directory e.g. "../password" to store the password in.
Create a file .htaccess and .htpasswd
Edit .htaccess with your favourite editor to contain the following:
AuthUserFile /path/to/password/.htpasswd
AuthGroupFile /dev/null
AuthName "Authentication Query Name"
AuthType Basic
place .htaccess in to be protected folder
Edit .htpasswd to contain the username and passwords. Syntax [username]:[md5-encrypted-password] Use a generator to make the encryption e.g.
foobar:Fkb3n2r1vsba
place .htpasswd in chosen directory and make sure you change the directories permission so only the server may access e.g. run chmod g+r,g+x,o-r,o-x password
If you run an Apache server just make a .htpasswd file and upload it to your main directory.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.