Aimad Majdou
Aimad Majdou

Reputation: 583

Protecting a directory using .htaccess and .htpasswd

I want to protect an admin folder in my PHP web site from other people. I created two files .htaccess and .htpasswd, but when I enter to the index page on this folder it doesn't show me that dialog where I have to enter the username and the password, here are the content of the files :

The .htpasswd file :

mateo21:$1$MEqT//cb$hAVid.qmmSGFW/wDlIfQ81
ptipilou:$1$/lgP8dYa$sQNXcCP47KhP1sneRIZoO0
djfox:$1$lT7nqnsg$cVtoPfe0IgrjES7Ushmoy.
vincent:$1$h4oVHp3O$X7Ejpn.uuOhJRkT3qnw3i0

The .htaccess file :

AuthName "Page d'administration protégée"
AuthType Basic
AuthUserFile "/var/www/sec/.htpasswd"
Require valid-user

I'm running Linux ubuntu and apache.

Upvotes: 1

Views: 587

Answers (2)

rdgd
rdgd

Reputation: 1446

If what @Jon Lin said doesn't work, then make sure you have

AllowOverride AuthConfig 

in your /etc/httpd/httpd.conf file

If you can't find your configuration file, then try searching for it in terminal...

locate "httpd.conf"

Or

find /etc/ -name "httpd.conf"

Upvotes: 0

Jon Lin
Jon Lin

Reputation: 143966

You need to deny everything first. Try:

Order Deny,Allow
Deny from all

AuthName "Page d'administration protégée"
AuthType Basic
AuthUserFile "/var/www/sec/.htpasswd"
Require valid-user

Upvotes: 1

Related Questions