Question:
I asked a question and Alvaro very kindly answered, only I don't understand codes and I don't know how to integrate with path's, the question and answer was this:
If I have 2 htaccess files in different directories -Do I need to create 2 htpasswd or 1 htpasswd is good for both?
A single htpasswd would work for both. The only thing is that you may have to define different path's in each htaccess file. But both will be able to use it without problems (example: it could be the case that you have different protected areas within your website but the usernames/passwords are common in both).
I will appreciate step by step information, thanks. (it is to make my page secure)
Answer:
The idea is that you have to define the path to the same .htpasswd
file in both .htaccess
files and that's the only thing that should change from one to the other (and not even that if you use absolute paths instead of relative ones).
For example, imagine you have this file system:
/
|-- Passwords
| `-- .htpasswd
`-- MiServidor
`- www
|-- Carpeta1
| `-- Subcarpeta1
| `-- .htaccess
`-- Carpeta2
`-- .htaccess
Where you have two .htaccess
files in different folders inside your web server, and a single .htpasswd
file outside the root directory of your web server.
So the .htaccess
in Subfolder1 would have this content:
Authtype Basic
AuthName "Escribe lo que quieras aquí"
AuthUserFile ../../../../Passwords/.htpasswd
Require valid-user
And the .htaccess
that is in Folder2 would have the content:
Authtype Basic
AuthName "Escribe lo que quieras aquí"
AuthUserFile ../../../Passwords/.htpasswd
Require valid-user
If you look closely, both have the same content, the only thing that changes is the path ( path ) to the .htpasswd
file because they are at different levels. But both could have the same content if the path was absolute from the root of the file tree ( /Passwords/.htaccess
or c:\Passwords\.htaccess
on UNIX/Linux and Windows respectively).