Allowing a Client-Specified Sort Order
Problem
You want to allow the end user to specify the order in which the listing should be ordered.
Solution
Users can supply QUERY_STRING arguments to modify the sort order:
| http://servername/directory/?C=D&O=D |
Or you can provide a form allowing the user to select the sort order, by placing the following form in a HeaderName file:
<form action="" method="get"> Order by by <select name="C"> <option value="N" selected="selected"> Name</option> <option value="M"> Date Modified</option> <option value="S"> Size</option> <option value="D"> Description</option> </select> <select name="O"> <option value="A" selected="selected"> Ascending</option> <option value="D"> Descending</option> </select> <input type="submit" value="Go" /> </form>
Discussion
Allowing the end user to control his experience is a powerful way to make your Web content more useful.
Unless this feature has been explicitly disabled using the IgnoreClient argument to IndexOptions, you will always be able to reorder the directory listing using the ?C= and ?O= QUERY_STRING options.
O (order) can be set to either A, for Ascending, or D, for Descending, and C (column) may be set to one of the following:
N—name of the file or directory
M—the last modified date of the file or directory
S—the size of the file in bytes
D—the description of the file, set with the AddDescription directive
The argument parsing routine will quit if it encounters an invalid argument.
With Apache 1.3, the syntax is, instead:
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access