-->
Previous | Table of Contents | Next |
Redirect does just thatredirects the request to another resource. That resource could be on the same machine or somewhere else on the Net. Also, the match will be a substring match, starting from the beginning. For example, if you entered the command
Redirect /newyork http://myhost.com/maps/states/newyork
then a request for
http://myhost.com/newyork/index.html
would get redirected to
http://myhost.com/maps/states/newyork/index.html
Of course, the second argument to Redirect can be an URL at some other site. Just make sure that you know what youre doing.
CAUTION:
Be wary of creating loops accidentally. For example,Redirect /newyork http://myhost.com/newyork/newyorkcan have particularly deleterious effects on the server.
You read earlier that theres a more elegant way of activating CGI scripts than by using ScriptAlias. You can use the AddType directive and create a custom MIME type, like so:
AddType application/x-httpd-cgi cgi
When the server gets a request for a CGI file, the server maps to that MIME type and then catches itself and says, I need to execute this rather than just dish it out like regular files. Thus, you can have CGI files in the same directories as HTML, GIF, and all your other files.
When Apache is given a URL to a directory instead of to a particular file as in this example:
http://myhost.com/statistics/
Apache first looks for a file specified by the DirectoryIndex directive in srm.conf. In the default configs, this file is index.html. You can set a list of files to search for or even an absolute path to a page or CGI script:
DirectoryIndex index.cgi index.html /cgi-bin/go-away
The preceding directive says to look for an index.cgi file in the directory first. If that cant be found, look for an index.html file in the directory. If neither can be found, redirect the request to /cgi-bin/go-away.
If the Apache server fails to find a match, Apache will createcompletely on-the-flyan HTML listing of all the files available in the directory.
There are quite a few ways to customize the output of the directory indexing functionality. First, you need to ask yourself if you care about seeing things such as icons and last-modified times in the reports. If you do, then you want to turn to
FancyIndexing On
Otherwise, youll just get a simple menu of the available files, which you may want for security or performance reasons.
If you choose to use the FancyIndexing option, you must ask whether you need to customize it further and, if so, how. The default settings for the directory indexing functionality are already pretty elaborate.
The AddIcon, AddIconByEncoding, and AddIconByType directives customize the selection of icons next to files. AddIcon matches icons at the filename level by using the pattern
AddIcon iconfile filename [filename] [filename]
Thus, for example, the following line
AddIcon /icons/binary.gif .bin .exe
means that any file that ends in .bin or .exe should get the binary.gif icon attached. The filenames can also be a wildcard expression, a complete filename, or even one of two special names: ^^DIRECTORY^^ for directories and ^^BLANKICON^^ for blank lines. Thus, you can see lines like these:
AddIcon /icons/dir.gif ^^DIRECTORY^^ AddIcon /icons/old.gif *~
Finally, the iconfile can be a string containing the icon files name and the alternate text to put into the ALT attribute. So, your examples should really be
AddIcon (BIN,/icons/binary.gif) .bin .exe AddIcon (DIR,/icons/dir.gif) ^^DIRECTORY^^
The AddIconByType directive is a little bit more flexible and probably comes more highly recommended in terms of actual use. Rather than tie icons to filename patterns, it ties icons to the MIME type associated with the files. The syntax is very roughly the same:
AddIconByType iconfile mime-type [mime-type]
mime-type can be either the exact MIME type matching what youve assigned a file, or it can be a pattern match. Thus, you see entries in the default configuration files like the following:
AddIconByType (SND,/icons/sound2,gif) audio/*
Using pattern matching is more robust than trying to match against filename suffixes only.
AddIconByEncoding is used mostly to distinguish compressed files from other types of files. This makes sense only if used with AddEncoding directives in your srm.conf file. The default srm.conf has these entries:
AddEncoding x-gzip gz AddEncoding x-compress Z AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
The AddIconByEncoding option sets the icon next to compressed files appropriately.
The DefaultIcon directive specifies the icon to use when none of the patterns match a given file when the directory index is generated:
DefaultIcon /icons/unknown.gif
Its possible to add text to the top and the bottom of the directory index listing. This capability is very useful as it turns the directory indexing capabilities from just a UNIX-like interface into a dynamic document interface. There are two directives to control this: HeaderName and ReadmeName which specify the filenames for the content at the top and bottom of the listing, respectively. These directives are shown as follows in the default srm.conf file:
HeaderName HEADER ReadmeName README
When the directory index is being built, Apache will look for HEADER.html. If it finds it, itll throw the content into the top of the directory index. If it fails to find that file, itll look for just HEADER. If it finds HEADER, it will presume that the file is plain text and do things such as translate < characters to the < character sequence, and then insert it into the top of the directory index. The same process happens for the file README, except that the resulting text goes into the bottom of the generated directory index.
Previous | Table of Contents | Next |