Learning notes for viewing Apache index directories

Source: Internet
Author: User


When browsing some image file sites, you will find that the website directory can browse the file (folder) list. Here are two examples: NetEase Open-source image and Ubuntu. As long as the Web server can enable or disable indexing for Apache-based websites (directory browsing), How Can I disable and enable display Directory indexing?


1. Disable Apache from displaying directory indexes
Method 1. Modify the Apache configuration file [httpd. conf]
(1) directory configuration

<Directory/home/www.111cn.net/teddysun ">
# Options Indexes FollowSymLinks
Options FollowSymLinks
AllowOverride None
Order allow, deny
Allow from all
</Directory>

Change Options Indexes FollowSymLinks to Options FollowSymLinks.

That is, Apache cannot display the directory structure.
Explanation: The function of Indexes is to display the directory structure when no index.html file is specified in the directory. If Indexes is removed, Apache will not display the list of directories.

(2) virtual machine configuration

<Virtualhost *: 80>
ServerName domain
ServerAlias domains
DocumentRoot/home/www/teddysun
CustomLog/home/www/teddysun/logs/access. log combined
DirectoryIndex index. php index.html
<Directory/home/www/teddysun>
Options + Includes-Indexes
AllowOverride All
Order Deny, Allow
Allow from All
</Directory>
</Virtualhost>

Add-The symbol also prevents Apache from displaying the directory structure.
Explanation: Before Indexes, adding + indicates that directory browsing is allowed; adding-indicates that directory browsing is prohibited.

Method 2: modify the. htaccess file
Modify the. htaccess file in the root directory of the website and add the following code (if there is no. htaccess file, create it ):

<Files *>
Options-Indexes
</Files>

Explanation:Before Indexes, add + to allow directory browsing; add-to prohibit directory browsing.

II. Enable and customize Apache display directory index styles

(1) modify the Apache configuration file [httpd. conf]

<Directory/home/www/teddysun ">
Options Indexes FollowSymLinks
IndexStyleSheet "/css/style.css"
IndexOptions FancyIndexing HTMLTable ScanHTMLTitles FoldersFirst NameWidth = 85 DescriptionWidth = 128 IconWidth = 16 IconHeight = 16 VersionSort Charset = UTF-8
AllowOverride all
Order allow, deny
Allow from all
</Directory>

Description: If Indexes is written to the Options option, the directory browsing function is enabled. Apache installed through yum in CentOS6 opens the directory browsing by default, but the directory cannot be displayed when you access the home page through a browser, because/etc/httpd/conf. d/welcome. in the conf file, there is a-symbol before Indexes, that is, Apache disables the directory browsing function of the home page by default.

(2) custom index (Directory Browsing) styles
The IndexOptions option in the previous step can customize the index (Directory Browsing) style, as shown below:
Enable directory browsing modification for FancyIndexing
HTMLTable: create a simple table with FancyIndexing for directory browsing and modification.
ScanHTMLTitles search HTML titles
FoldersFirst Directory takes precedence over
NameWidth = 85 indicates that the file name can contain a maximum of 85 English characters.
DescriptionWidth = 128 indicates the number of characters that the description can display.
IconWidth = 16 Icon width (pixel)
IconHeight = 16 Icon height (pixel)
VersionSort version sorting. If this option is not available, it will be sorted in the pinyin order.
Charset = character set for UTF-8

Others such:
Please refer to the link for AddAltClass, IconsAreLinks, IgnoreCase, IgnoreClient, ShowForbidden, details, SuppressDescription, details, SuppressIcon, references, SuppressRules, SuppressSize, TrackModified, and Type.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.