Archive

Posts Tagged ‘apache’

Customizing Directory Listing on Apache

August 28th, 2009 paul No comments
  • When a directory is requested as URL and no default file is present, Apache generates an HTML page of the contents of the directory. The default layout is fine but not the best looking.
  • You can use CSS to format the page and add a few tweaks. It’s pretty simple to do and a good practice.
  • You need to have a Linux OS running Apache httpd-2.2.3-22. It doesn’t have to be the exact same version.
  • In order to test this concept, add a directory with some files and subdirectories in the document root, which is normally /var/www/html/. So you should have something like /var/www/html/test/. In that directory create or copy in some files and directories.
  • If you go to http://your_server/test/ you will see list of the files and directories in /var/www/html/. You can click on them to download them.
  • Before editing /etc/httpd/conf/httpd.conf back it up.
  • >cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.20090203
  • Editing /etc/httpd/conf/httpd.conf
  • Search for ‘IndexOptions’ and you should see the following line:
  • IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable
  • Edit the line by adding FoldersFirst
  • So you should see this now.
  • IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable FoldersFirst
  • Add this line below the line you just edited.
  • IndexStyleSheet “/css/directory.css”
  • That line specifies to use css and what css file to use.
  • Save and close the file.
  • Now create directory called css and create a file called directory.css. So on Linux file system you should have this: /var/www/html/css/directory.css
  • Add following lines into /var/www/html/css/directory.css
  • body {background-color:#E6E6FA;color:black;}
  • /etc/init.d/httpd restart
  • Now refresh the web browser that’s pointed at http://your_server/test
  • You should notice the difference.
Categories: short tip Tags: