.htaccess
April 1, 2022
10:13 AM
Example#1
RewriteEngine On
    <Files *>
    Deny from all
    </Files> 
Password Protect Directories
To do this you’ll need two files, .htaccess and .htpasswd. The .htpasswd file includes some encryption, so use a tool like Htpasswd Generator to create the file. The .htaccess file should include this code;
AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /path/to/.htpasswd
Require valid-user
From <[link]> 
Apache .htaccess Guide & Tutorial >>
Disable directory listings
Preventing directory listings can be very useful if for example, you have a directory containing important '.zip' archive files or to prevent viewing of your image directories. Alternatively it can also be useful to enable directory listings if they are not available on your server, for example if you wish to display directory listings of your important '.zip' files.
To prevent directory listings, create a .htaccess file following the main instructions and guidance which includes the following text:
IndexIgnore *
The above lines tell the Apache Web Server to prevent directory listings of directories and files within the directory containing the .htaccess file. The '*' represents a wildcard, this means it will not display any files. It is possible to prevent listings of only certain file types, so for example you can show listings of '.html' files but not your '.zip' files.
To prevent listing '.zip' files, create a .htaccess file following the main instructions and guidance which includes the following text:
IndexIgnore *.zip
The above line tells the Apache Web Server to list all files except those that end with '.zip'.
To prevent listing multiple file types, create a .htaccess file following the main instructions and guidance which includes the following text:
IndexIgnore *.zip *.jpg *.gif
The above line tells the Apache Web Server to list all files except those that end with '.zip', '.jpg' or '.gif'.
Alternatively, if your server does not allow directory listings and you would like to enable them, create a .htaccess file following the main instructions and guidance which includes the following text:
Options +Indexes
The above line tells the Apache Web Server to enable directory listing within the directory containing this .htaccess file. You can also reverse this to disable directory listings by replacing the plus sign before the text 'Indexes' with a minus sign. e.g. 'Options -Indexes'.
You can also include a default description for the directory listings that is displayed at the top of the page by placing a file called 'HEADER' in the same directory. The contents of this file are displayed before the list of directory contents. You can also include a footer, by creating a file called 'README'. The contents of this file are displayed after the list of directory contents.
From <[link]> 