Biblioteca de cunoștințe

Adding Directory Indexing to Apache 2  Tipărire

This is a guide on how to add Directory Indexing to Apache 2 to so that it will look just like Apache 1.x Indexing with icons.

There are two different ways to do this if you have full root control over the entire server you can change the Apache 2 httpd.conf so that it will reflect server wide.  There is also away to set this on a per user, per domain basis in case you want to just set this for one user or domain or if you are on a shared hosting plan.
<!--more-->
First we will cover how to do this on a shared server with a .htaccess file.

You will need to create or edit a .htaccess file, and this file will need to be at the web accessible level in the folder e.g. www or public_html or httpdocs

edit the .htaccess with your file manger or download it with ftp and edit it on your computer add the following:

<code>
IndexOptions FancyIndexing VersionSort
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
</code>

<code>
AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*
</code>

<code>
AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core
AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^
</code>

<code>
DefaultIcon /icons/unknown.gif
ReadmeName README.html
HeaderName HEADER.html
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
</code>

Save and Exit

If you edited this via file manger you should be good to go if you edit it on your PC before to upload it to the web root folder.

Browser to a folder on your web site that will show a directory listing, if you see words next to your files instead of icons make sure that /icons/ folder exits on your server.  You can do this by going to:

<code>
http://www.yourdomain.com/icons/
</code>

If this folder does not show files in it or does a 404 not found.  You can download the stock apache icons from me.

With (SSH) shell access do this:

<code>
[root@dev ~]# cd public_html (or where ever your root web sites are)
[root@dev ~/public_html]# wget <a href="http://www.abouteye.com/downloads/icons.zip">http://www.abouteye.com/downloads/icons.zip</a>
[root@dev ~/public_html]# unzip icons.zip
</code>

If you do not have SSH access you can just right click on the URL above and select Save File As.  Unzip this on your pc and upload it into public_html folder as the folder name icons

Then you should be good to go.

Now if you have Full Root Access you can do the following so that this takes effect on all web sites that have directory listing enabled.

<code>
[root@dev ~]# nano /usr/local/apache/conf/httpd.conf
</code>
do a find and make sure that this does not already exist for /icons/ if it does not exist add these entries:

<code>
Alias /icons/ /usr/local/apache/icons/
</code>

<code>
<Directory "/usr/local/apache/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</code>

<code>
</Directory>
</code>

Then go down to around some of the other AddType entries like:

<code>
AddType application/vnd.wap.wmlscriptc .wmlsc
</code>

Then you will need to add these lines if they do not already exist.

<code>
<IfModule mod_autoindex.c>
</code>

<code>
IndexOptions FancyIndexing VersionSort
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
</code>

<code>
AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*
</code>

<code>
AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core
AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^
</code>

<code>
DefaultIcon /icons/unknown.gif
ReadmeName README.html
HeaderName HEADER.html
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
</code>

<code>
</IfModule>
</code>

Exit and Save

Now you need to make sure that there are not any syntax errors in Apache conf since you just edited.  If you have syntax errors the Apache web server will fail to start.

<code>
[root@dev ~]# /etc/init.d/httpd conftest
</code>

if this comes back with Syntax OK, go ahead and restart the service so that the change we made will take effect.

<code>
[root@dev ~]# /etc/init.d/httpd restart
</code>

now give it a seconds or two and make sure that it is running by doing a status

<code>
[root@dev ~]# /etc/init.d/httpd status
</code>

Now go and check that your directory listings are working correctly.

Răspunsul a fost util?