29.6. Setting Per-Directory Options

Apache allows you to specify different options for certain directories—either for all virtual servers or just a single one. Including directories, you can actually set options that apply to three types of objects on your Apache server:

Directory The options apply to a specified directory and all files in it or in the subdirectories that it contains.

Files The options apply to files with a specified name in any directory.

Location The options apply to any files or directories requested by a URL whose path starts with the specified location. For example, in the URL www.example.com/foo the path would be /foo.

Whenever Apache processes a request, it checks for the options that apply to it in a fixed order. Those from directory sections and .htaccess files are read in order so that the most specific directories are checked first. They are then followed by files and then location sections. Options from the virtual server to which the request was made (if any) are then read, and finally options from the default server.

This means that options set for a directory will override the same options set in a higher level directory, or in the virtual server of which it is a member. To set options for a directory, files, or a URL location, follow these steps:

1.
Even though the options you are going to set apply to a directory, they must be defined under one of the virtual servers or the default server. If they are under a virtual host, they will apply only to requests to that server for files in the chosen directory or URL location. If they are under the default server, however, requests to any virtual host for files in the directory will be affected.

On the module's main page, click on either the Default Server icon or the icon for a virtual server to which you want the directory options to be limited. For directories, it is usually simplest to put their options under the default server as each virtual host typically has its own separate document root directory. URL location options, however, should be put under the virtual server to which they are related because the same URL path may be used in different ways on more than one virtual host. The same goes for file options.

2.
On the server options page that appears (shown in Figure 29.4), scroll down to the Create Per-Directory, Files, or Location Options form.

3.
From the Type menu, choose one of the options previously described.

4.
If you are setting options for a directory, enter it into the Path field such as /home/example/www/images. You can also enter a wildcard path such as /home/example/w*, which will cause the options to apply to all directories that match.

If the options are being set for a URL location, enter the part of the URL after the hostname into the Path field, such as /images. You can also use shell wildcard characters like * and ? in the URL as well. If setting options for files, enter a filename into the Path field such as secret.html. Once again, wildcard characters can be used in the filename, for example secret*.

5.
If you want to be able to use complex regular expressions in the directory, filename, or URL location, set the Regexp? field to Match regexp. This will allow you to use Perl regular expression characters like [, ], +, . and * in the path.

6.
Click the Create button to add the new directory section to the Apache configuration. The virtual server options page will be displayed again, but with a new icon for the directory.

Now that you have created a new icon for a directory, URL location, or filename, you can set options that apply to it. One of the most common per-directory changes is configuring how files are listed when a browser requests a directory with a URL like www.example.com/images/. By default, if there is an index.html file in the directory it will be displayed. If not, a page listing all files that it contains will be shown instead.

If you want to change the name of the index file, the style of the directory listing, or any other settings related to indexing, follow these steps:

1.
Click on the icon for the directory that you want to configure on the virtual server options page. This will take you to the directory options page shown in Figure 29.5.

2.
Click on the Directory Indexing icon to bring up a form for setting indexing and listing options.

3.
To change the appearance of directory listings, set the Directory index options field to Selected below and change the fields in the box provided. The defaults will generate a very plain list of files, but you can enhance it by setting the following options:

Display fancy directory indexes If enabled, the list of files will include their icon, size, and modification date.

Display HTML title as description If enabled, the description for HTML files will be taken from their <title> tags.

Icon height This option allows you to change the height of icons included in the directory listing. If it is set to Default, the height of the standard Apache options will be used.

Icon width Like the previous option, this one allows you to specify the width of icons in the directory listing.

Allow user sorting of column When this is enabled, users will be able to sort the list of files by clicking on the column headings, assuming they are being displayed.

Show file descriptions If enabled, the directory listing will include a description for each file taken from its MIME type or HTML title.

Output HTML header tags When enabled, the directory listing will include the normal <html> and <head> tags that should begin every HTML page. You will only want to turn it off if you are providing your own header and footer files.

Show last modified times When enabled, the directory listing will include the last modified date for each file.

Show file sizes When enabled, the listing will include the size of each file.

Include icon in link If this option is enabled, the icon in the listing will be a link to the file itself. Otherwise, only the filename is a link.

Filename width This option controls the length of the filename column in the directory listing. You can either enter a number of characters or * to size the column to the length of the longest filename.

Description width This option controls the length of the description column in the directory listing, if any. You can either enter a number of characters or * to size the column to the length of the longest description.

Display directories first If enabled, the listing will show any directories above any files, regardless of any other files.

The options that are available depend on the version of Apache that you have installed on your system. Those listed above are valid for version 1.3.19, but if you have a newer release more options may be available.

4.
If you want Apache to return a file other than the default (usually index.html) when a browser requests the directory, enter a list of filenames into the Directory index files field. More than one can be entered and the first that is found will be used. If none of the index files are found, a directory listing using the options chosen in Step 3 will be returned to the browser instead.

5.
To have the web server ignore certain files when generating a list of files in the directory, enter their filenames into the Files to ignore in directory index field. You can use shell wildcards in the regular expressions, such as *.doc.

6.
To have an HTML file inserted at the start of the directory listing, enter its filename (relative to the directory) into the Directory index header file field.

7.
Similarly, to have a filename added at the end of the directory listing, enter its name into the Directory index footer file field.

8.
To control the default ordering of the directory, deselect Default in the Sort directory index by field and select an order and column to sort on from the two menus next to it.

9.
You can set descriptions for files by filling in the Directory index descriptions table. In the table's empty row, enter a short message describing the file in the Description column and a list of filenames or wildcard names in the Filenames column.

Because only one empty row is shown at a time, you will need to revisit this page after adding each description if you want to enter more than one.

10.
Finally, click the Save button at the bottom of the page to store your changes and return to the directory options page. To activate them, click the Apply Changes link anywhere in the Apache module.

Most of these options can be set for an entire virtual server by clicking on the Directory Indexing icon on the Virtual Server Options page as well. In this case, they will apply to all files requested from the virtual host unless overridden by options for a directory or URL location.

On the directory options page, there are many more icons on which you can click to set options that apply only to that directory, URL path, or filename. Some of these are explained in later sections of this chapter, such as Section 29.7 “Creating Aliases and Redirects” and Section 29.13 “Password Protecting a Directory”.

You can change the directory, filenames, or URL location to which settings apply by using the Options apply to form at the bottom of the Directory Options page. It has the exact same fields as the creation form described at the start of this section. If you make any changes, click the Save button to update the Apache configuration and then the Apply Changes link to make them active. You can also click on Delete to remove the directory configuration and all its options.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.166.76