How is the integration of 2 htaccess with ptpasswd?

6

Ask a question and very kind Alvaro has answered, only that I do not understand codes and I do not 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 does it work for both?

A single htpasswd would be good for both. The only thing is that you may have to define different path's in each htaccess file. But both can use it without problems (example: it could be the case that you have different protected areas within your website but users / passwords are common in both).

I will appreciate information step by step, thank you. (is to make my page safe)

    
asked by Lita San 22.04.2016 в 20:36
source

1 answer

2

The idea is you have to define the path to the same file .htpasswd in the two files .htaccess and that's the only thing that would have to change from one to another (and not even that if you use absolute paths instead of relative ).

For example, imagine that you have this file system:

/
|-- Passwords
|   '-- .htpasswd
'-- MiServidor
    '- www
        |-- Carpeta1
        |   '-- Subcarpeta1
        |      '-- .htaccess
        '-- Carpeta2
            '-- .htaccess

Where you have two file .htaccess in different folders within your web server, and a single file .htpasswd outside the root directory of your web server.

Then, the .htaccess that is 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 notice, both have the same content, the only thing that changes is the path ( path ) to the file .htpasswd because they are at different levels. But both could have the same content if the path were absolute from the root of the file tree ( /Passwords/.htaccess or c:\Passwords\.htaccess in UNIX / Linux and Windows respectively).

    
answered by 25.04.2016 в 06:41