If there are any misconfigured rules or incorrect syntax in an .htaccess file, users see an “Internal Server Error” message when they visit a page in the same directory. Be very careful when you make any changes to an .htaccess file.
Code to protect directories and subdirectories
You can protect files, directories and subdirectories to help prevent unauthorized access. The following parameters are used below to protect the folders:- AuthType Basic: This specifies the web server’s authentication method.
- AuthName “Dialog Prompt”: This provides the title of the authentication dialog box.
- AuthUserFile path: This instructs the web server where to look for the username/password file. Replace path with the relative path to your .htpasswd file.
- Require valid-user: This instructs the web server which users in the .htpasswd file have access to the folder. The valid-user portion indicates that the folder is viewable to all users in the file.