apache tutorial - Directory Index Listings in htaccess - apache - apache web server - apache server - apache2
Directory index listings in htaccess
htaccess directory listing
- we can enable directory index listings for directories on our web site that do not have a default directory index page.
How to enable and disable directory index listings using an .htaccess file:This article describes you on how to enable and disable apache directory index listings using an htaccess file ( secure htaccess directoryindex file ). we can configure the web server to display file listings for directories that do not have a directory index page.
Using directory index listings:
- By default, on apache web servers, when visitors go to a URL that requests a directory, such as http://wikitechy.com/aboutus, the web server looks for the default directory index page.
- If the directory index page does not exist, the web server displays a 403 Forbidden error message. This is because directory index listings are disabled by default htaccess security reasons.
- Directory index listings can be handled as,
- htaccess to allow directory listing - Enable directory index listings
- htaccess hide directory - Disable directory index listings
Enable directory index listings: htaccess to allow directory listing
- In some cases, however, we may want to enable index listings for a directory.
This htaccess directory listing directive enables standard indexing, where the index listing shows only the filenames.
we can also enable “fancy” indexing, where the index listing shows filenames, their file sizes, and when they were last modified.Now we can add the following line to the .htaccess file:
Disable directory index listings - htaccess hide directory
Directory index listings are disabled by default, so we only need to explicitly disable them if they were previously enabled in an .htaccess file.To do this, use a text editor to modify the Options line in the .htaccess file as follows:
Similarly, if we have enabled fancy indexing and want to disable it, leave standard indexing enabled, use a text editor to modify the Index Options line in the .htaccess file as follows:
Directory Listing - htaccess directoryindex - Configuration:Here we describe various types of things that the server can send when we request a directory rather than an individual file.
1. Trailing Slash Redirection:
- we request a directory without including the trailing slash in its name (i.e. http://wikitechy.com/dir ratherthan http://wikitechy.com/dir/), then Apache must send a htaccess redirect to add the trailing slash to the URL. This is necessary so relative hyperlinks will work in the resulting file.
2. Directory Indexes:
- When a directory is requested, apache server may be configured to send a particular file within that directory automatically.
- This is configured with the Directory Index directive.
- directoryindex htaccess - It can list one or more files that Apache should search for in the directory, with the first existing file being returned to the client.
3. directoryindex htaccess
- If no file from the DirectoryIndex directive can be located in the directory, then mod_autoindex can generate a listing of the directory contents.
- This is turned on and off using the Options directive.
For example, to turn on directory listings for a particular directory (htaccess allow directory) , we can use:
- To prevent directory listings (for security purposes, for example), we should remove the Indexes keyword from every Options directive in our configuration file.
- To prevent them only for a single directory, we can use:
- we would listings to be enabled, but we want to omit particular files, we can use the Index Ignore directive.
- For example, to omit any filename starting with tmp and also the parent directory link (..), we could use: