• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to protect web directories using .htaccess

{{postValue.id}}

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

1

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

2

Tags:
isaiah
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

May i know What are the types of authentication can be used for apache web server?

A

There are two types of authentication which are Basic and digest authentication. These two can be user for apache webserver

Q

What are the difference between basic and digest authentication?

A

The differences are basic & digest authentication are
Basic authentication uses base64 encoding which is less secure, whereas the digest authentication uses hash algorithm which is more secure.

Q

What is the ownership name for apache webserver directory on ubuntu ?

A

The apache web directory uses "ww-data" for both user & group at ubuntu/debian

Q

What are all the files does htpasswd contains ?

A

The htaccess file should contain the following:

AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /path/to/.htpasswd
Require valid-user

Q

Where to find apache default configuration file on ubuntu?

A

You can find the default configuration under /etc/apache2/sites-available/000-default.conf

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help keel johnston ?
Unhide the folders on windows Explorer

Give any solutions to unhide folder using command prompt?

forum3

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.