How to protect web directories using .htaccess
To protect web directories with password using .htaccess File
This article helps you to protect other search engines from accessing information of site when it’ s in the development phase.
To set password for Directories
---------------- On RedHat/CentOS based systems ----------------
vi /etc/httpd/conf/httpd.conf
---------------- On Debian/Ubuntu based systems ----------------
nano /etc/apache2/sites-available/000-default.conf
To find root of Apache Document directory
On Apache 2.2 Version
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride All allow,deny Allow from all
On Apache 2.4 Version
Options Indexes Includes FollowSymLinks MultiViews AllowOverride All Require all granted
To save file and restart
--------------- On Systemd -------------------
systemctl restart httpd [On RedHat based systems] systemctl restart apache2 [On Debian based systems]
--------------- On SysV init -----------------
service httpd restart [On RedHat based systems]
service apache2 restart [On Debian based systems]
To generate user name and password
Syntax
htpasswd -c filename username
-c option helps to keep encrypted username and password
To create a new directory
mkdir /home/linuxhelp
To generate username and password
htpasswd -c /home/linuxhelp/test-file linuxhelp
To change ownership of file
---------- On RedHat/CentOS based systems ----------------
chown apache: /home/linuxhelp/test-file
chmod 640 /home/linuxhelp/test-file
----------- On Debian/Ubuntu based systems ----------------
chown www-data /home/linuxhelp/test-file
chmod 640 /home/linuxhelp/test-file
To request password to access targeted directory
vi /var/www/html/.htaccess AuthType Basic AuthName " Restricted Access" AuthUserFile /home/linuxhelp/test-file Require user linuxhelp
To save file and setup
http://ip-address
Comments ( 0 )
No comments available