Customize Apache index styles

Source: Internet
Author: User
Tags sorted by name support microsoft qmail
Customize Apache index styles

# Indicates that the index mode (directory browsing) is enabled)
Options Indexes

Indexoptions fancyindexing scanhtmltitles namewidth = 128 descriptionwidth = 256 htmltable versionsort foldersfirst

Available parameters, meaning:

# Scanhtmltitles: search HTML titles
# Namewidth: number of bytes displayed for file life
# Descriptionwidth: Description of the number of bytes displayed
# Htmltable: HTML format allowed
# Foldersfirst: Directory priority

Suppresslastmodified: The latest modification time cannot be displayed in the directory.

# Index exclusion syntax

Indexignore header.html footer.html

Header.html footer.html files are not indexed (directory browsing.

# Index header embedded file
Headername/data/index/header.html

# Index bottom embedded file
Readmename/data/index/footer.html

Readmename: Specifies the footer template of the directory list. After an HTML file is specified, Apache loads the webpage at the bottom of the directory list. (Note: The file path is relative to the root of the List Directory, not to the system root or website root .)
Headername: Specifies the header template of the directory list. After an HTML file is specified, Apache will replace the dull index of... on the default directory list with this webpage ...... (Note: The file path is relative to the root of the List Directory, not to the system root or website root .)

# Default index sorting method
Indexorderdefault ascending date

# Disable the server flag
Serversignature off

Customized Apache ONE Directory Index display style
The mod_autoindex module is responsible for directory indexes in Apache. It converts the result of the current directory to an HTML page. By default, many types of files are uncomfortable. For example, the file name is too narrow (only 23 bytes in size), the icon is too large, and many file types are not associated. Fortunately, Apache developers have long thought of this and provided customized commands. For details about the official website, go to the superchain above.

Index style control command:
Indexoptions directive // dirctive is a command option. See the following example.

The following describes common settings (all written in the httpd. conf file ):
Modify the width of an automatic Directory Index
By default, Apache uses 23 bytes in width for each column by default, which is too short for file names. Generally 60 bytes
Indexoptions namewidth = 60

Modify Icon size
The default value is 24. After testing, we found that 16 is better.
Indexoptions iconheight = 16
Indexoptions iconwidth = 16

Directory priority
By default, files are prioritized, which is inconsistent with our usual habits. Change it.
Indexoptions foldersfirst

Sort versions
Needless to say, add it. The Chinese characters are sorted in the pinyin order.
Indexoptions versionsort

Icon Optimization
The default icons are quite ugly, and there are still many file types without icons. Because Solaris does not support Microsoft-defined document types, these files are displayed using question mark icons, sun may have an attitude towards Microsoft, but I don't think so. Everything should be clear.
The custom file icon consists of two steps. You can use the icon tool to capture commonly used icons, such as Word, Excel, powerpint, rar, and PDF. In addition, the default directory icon looks uncomfortable. simply move all the items in the window. After that, save all these icons (in GIF or PNG format) to the/usr/local/apache2/icons directory. For the visual icon, I directly replaced the file named folder.gif with a soft icon.
Next, use the addicon command to associate the icon with the file type.
Addicon/icons/word.gif. Doc. Doc
Addicon/icons/excel.gif. xls. xls
Addicon/icons/rar.gif. rar. rar
Addicon/icons/srm.gif. SRM. SRM
Addicon/icons/powerpoint.gif. ppt. ppt
Addicon/icons/access.gif. MDB. MDB

The above is my favorite file type. Do not forget to add the case.
After that, restart Apache. However, several types of L are not displayed, such as rar, SRM, and MDB.
I analyzed the configuration file carefully and found that it may be related to the file type.
Apache has a file specifically responsible for the file type: mime. types, which classifies each file in detail. For example, application, image, audio, and video. I searched it all over without the above three types, so I added the following definition before:
# MIME type extensions
Application/WinRAR RAR
Application/SRM
Application/access MDB

Restart Apache and OK.

Simple configuration of Apache Directory Index
By using Apache to configure simple directory indexes, the publisher can easily browse and download contents under the directory.

Procedure: (The following are all operations with root privileges)

1. install Apache: Pacman-s Apache

2. Configure Apache: VI/etc/httpd/CONF/httpd. conf

# Administrator's email address.

Serveradmin [email] HeirJoe@gmail.com [/Email]

# Server name, write IP address without Domain Name

Servername my IP: 80

# Main directory address

DocumentRoot "/path/to/Server"

# Set the permission of the default home directory. You need to use

  

Order deny, allow

Allow from all

  

# Use an alias to convert the absolute path of the system to the relative path relative to DocumentRoot

Alias/home "/home/httpd"

# Configure browsing DIRECTORY Options

  

# The option is the index method.

Options Indexes

# Index options, directory priority

Indexoptions fancyindexing foldersfirst

# Index exclusion options

Indexignore header.html footer.html

# Index header embedded file (only the relative path relative to the HTTP main directory can be used, rather than the absolute path of the system)

Headername/home/html/header.html

# Index the embedded file at the bottom (same as above, "/home" uses an alias, and you must set permissions for that directory)

Readmename/home/html/footer.html

# Disable the server flag

Serversignature off

# Control level obtained by using the. htaccess File

AllowOverride none

# Access Control

Order allow, deny

Allow from all

  

So many modifications have been made, and the others are system default. Security and performance are not taken into account, and they can basically run normally.

3. run Apache: httpd-K start

There are so many simple configurations, and there are many more Apache configurations and combinations. I will study them in detail later.

Personalized apach2 directory list

The personalized list of apach2 directories depends on the use and cooperation of various commands in the modautoindex module. Read the modautoindex module document in apache2.0.

URL: [url] http://httpd.apache.org/docs/2.0/mod/mod_autoindex.html#/url]

Before starting, see the demo address of a personalized directory list: [url] http://nanu.8866.org/download#/url]

Next, let's start:

1. Modify the httpd. conf file

Customize directories to be customized:

<Directory "/www/download">
Options indexes followsymlinks
Indexoptions fancyindexing scanhtmltitles namewidth = 25 descriptionwidth = 128 versionsort foldersfirst
Indexignore favicon. ICO header.html footer.html Images
Headername header.html
Readmename footer.html
Adddescription "Qmail installation package" qmail.tar.gz
Adddescription "putty0.58" putty.exe
Adddescription "my MSN Avatar: P" msn.gif
Indexorderdefault ascending name
AllowOverride none
Order allow, deny
Allow from all
</Directory>

Instructions:

Scanhtmltitles: If the directory contains HTML files, Apache automatically reads the <title> ...... Section. Use the title of the HTML file as the description section in the List Directory .. (Note: loading this command will increase the CPU load !)

Namewidth = 25: Specify the directory list to display the file/directory name up to 25 bytes. If you use * as the value, the maximum file name is automatically used.

Descriptionwidth = 128: Specify the directory list to display the file/directory description up to 128 bytes.

Versionsort: If the directory contains different versions of the same file, Apache Automatically sorts the file by version number.

Foldersfirst: Listing folders first will make the display look better!

Indexignore: The file/directory set after it is not displayed in the directory list.

Headername: Specifies the header template of the directory list. After an HTML file is specified, Apache will replace the dull index ..... A personalized header webpage is displayed. (Note: The file path is relative to the root of the List Directory, not to the system root or website root !)

Readmename: Specifies the footer template of the directory list. After an HTML file is specified, Apache loads the webpage at the bottom of the directory list. (Note: The file path is relative to the root of the List Directory, not to the system root or website root !)

Adddescription: If you want to set a description for a file, use this command in the format of adddescription "Description.

Indexorderdefault ascending name: specifies that the directory list is sorted by name.

Of course, you can also customize a lot of other content, including setting an icon for each file. Read the document.

Create header.htmland footer.html

These two files are the first and last pages in the List Directory, and they are also the key to personalization. In fact, this Part has nothing to do with the Apache level. It mainly depends on the level of your webpage.

The format of the two files is as follows:

Header.html:

<! -- Start with personalized content -->
You can add personalized content, images, Flash files, tables, and so on here!
<! -- End of personalized content -->
<! -- Embedded List Directory -->
<Table>
<TD>
<Tr>
Footer.html:

</Tr>
</TD>
</Table>
<! -- Directory list embedding ends -->
<! -- Start with personalized content -->
You can add personalized content, images, Flash files, tables, and so on here!
<! -- End of personalized content -->

As you can see, the self-defined original directory inserts the apachecontents between header.htm </table> </tr> </TD> and footer.html </TD> </tr> <// table>, the other parts of the two files can be customized.

After creating these two files, you can restart Apache and see how beautiful your customized directory is!

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.