how to sort apache directory listing in last modified order

14,796

First of all: my pet peeve, quoted from from the manual on .htaccess files:

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.

Second, more reading of the manual is also useful:

The IndexOrderDefault directive is used in combination with the FancyIndexing index option.

Translation: include the FancyIndexing option in the IndexOptions directive.
Then right below that in the manual:

IndexOrderDefault takes two arguments. The first must be either Ascending or Descending, indicating the direction of the sort. The second argument must be one of the keywords Name, Date, Size, or Description...

That results in the following:

<Directory /some/path>
   # Disable .htaccess files for performance:
   AllowOverride none

   # Enable automatic index generation for directories without a DirectoryIndex file 
   # and sort them by date:
   Options +Indexes 
   IndexOptions FancyIndexing
   IndexOrderDefault Descending Date
</Directory>
Share:
14,796

Related videos on Youtube

sukhjit dhot
Author by

sukhjit dhot

Updated on September 18, 2022

Comments

  • sukhjit dhot
    sukhjit dhot over 1 year
    # SET DISPLAY ORDER
    IndexOrderDefault Descending Name
    

    the above value is used to sort directory listing in decending name value how can i create the similiar results for sorting the directory in last modified order.i am using .htaccess.please don't show the alternative ways

    # SET DISPLAY ORDER
    IndexOrderDefault last modified 
    

    specify the default directory display order:

    here is what my .htaccess file look like

    RewriteEngine On
    RewriteBase /
     # Disable server signature
     ServerSignature Off
    
    • HBruijn
      HBruijn over 9 years
      Your choice of Options -Indexes completely disables automatic index generation...
  • sukhjit dhot
    sukhjit dhot over 9 years
    hello sir you say using htaccess may lead to slow page load but personally i haven't noticed any diff in load time before or after.
  • HBruijn
    HBruijn over 9 years
    When AllowOverride enables the use of .htaccess files, httpd will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested. Apache must look for .htaccess files in all higher-level directories, in order to have a full complement of directives that it must apply. If a file is requested out of a directory /www/htdocs/example, httpd must look for these too: /.htaccess /www/.htaccess /www/htdocs/.htaccess /www/htdocs/example/.htaccess