APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Using .htaccess files to restrict access

© December 2005 Tony Lawrence

Every directory in a Apache website can have an optional .htaccess file. This can be used to require passwords to access the files therein or to redirect requests to other pages. Everything you can do in an .htaccess file can also be done in your web server's configuration file, but that can be a little intimidating and confusing for new web masters. The .htaccess is slightly less efficient, but easy to use.

Restricted Access

Let's say you want to restrict access to a certain subdirectory. Create .htaccess in that directory, and put this into it:

 AuthUserFile /www/data/.htpasswd
 AuthName "Login and Password Required"
 AuthType Basic
 <Limit GET>
 require valid-user

Note that AuthUserFile can be anywhere that the web server can read. You then have to create the .htpasswd file:

 htpasswd -c /www/data/.htpasswd username

That prompts for a password for "username" and that's it. You can add additional users with the same command; just leave off the "-c".

At some sites, we tell the user what name to use and they only have to remember the password. You can even prompt them or give them hints in the Authname string if that helps.

It's that easy. Tomorrow I'll cover using .htaccess to redirect requests and to help with security.

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> Using .htaccess files to restrict access

Inexpensive and informative Apple related e-books:

Take Control of Upgrading to El Capitan

Photos: A Take Control Crash Course

Take Control of High Sierra

Take Control of the Mac Command Line with Terminal, Second Edition

Sierra: A Take Control Crash Course

More Articles by © Tony Lawrence

Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

May you live long enough to regret your opinions - (Tony Lawrence)

Linux posts

Troubleshooting posts

This post tagged:



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode

SCO Unix Sales, Support, & Service

Phone:  707-SCO-UNIX (707-726-8649Toll Free: 833-SCO-UNIX (833-726-8649)