Hide site content from prying eyes

Problem: Sometimes we need closed all our site from prying eyes, how we can do it?

How to set login and password for to view a site?

Solution: In this case help us htaccess file.

Step 1: Connect to our hosting use SSH

ssh user_name@host-name.com

Step 2: In the root directory make file .htpasswd use next command, where user_name - login for enter site and password you should enter after command execute

htpasswd -c .htpasswd user_name

Step 3: Make .htaccess file

vi .htaccess

Step 4: Add into the file:

Order deny,allow
Deny from all
RedirectMatch 404 /\\.(svn|git|hg|bzr|cvs)(/|$)
RedirectMatch 404 /README.md$
AuthName "Authorization required!"
AuthUserFile /home/user_name/.htpasswd #Replace on your path
AuthType Basic
Require valid-user
#Allow from #Uncomment and replace IP address, that don't to need block
Satisfy Any

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Leave Comment

Your email address will not be published. Required fields are marked *