mod_dir 與 mod_autoindex

最後更新: 2015-11-17

 

目錄

 


mod_dir

 

"mod_dir" Provides for "trailing slash" redirects and serving directory index files

"trailing slash" redirects 的 location header 是 FULL URL 的

https://datahunter.org/tc -> location: https://datahunter.org/tc/

Set Index Page

當訪問 /Folder/ 時會自動訪問 /Folder/filename  <- 順序是 index.html index.htm index.php

DirectoryIndex index.html index.htm index.php

DirectoryIndexRedirect

Configures an external redirect for directory indexes(出 "/" 還是 "/index.html")

Settings

  • on / temp: issues a 302 redirection to the index resource
  • off: does not issue a redirection. This is the legacy behaviour of mod_dir (DEFAULT)
  • permanent: issues a 301 (permanent) redirection to the index resource
  • seeother: issues a 303 redirection (also known as "See Other") to the index resource
  • 3xx-code: issues a redirection marked by the chosen 3xx code

DirectorySlash

Toggle trailing slash redirects on or off (Default: On)

 * DirectoryIndex will be evaluated only for directories requested with trailing slash.

 * Security Warning: mod_autoindex works correctly

A request with a trailing slash would show the index.html file

But a request without trailing slash would list the directory contents

 


mod_autoindex

 

Enable:

Options +Indexes
IndexOptions Charset=UTF-8

Disable:

Options -Indexes 

FancyIndexing:

# column headers are links that control the order of the display.

IndexOptions FancyIndexing
FancyIndexing

支援 IndexOrderDefault

IndexOrderDefault Ascending|Descending Name|Date|Size|Description

List Folders First

IndexOptions +FancyIndexing +FoldersFirst

* 必需要 Enable FancyIndexing

設定 ICON

Usage

AddIcon (ALT,/url/of/image.gif) filename

AddIcon [PathToIcon] [Extensions]

* ALT is the alternate text to be displayed if the image does not load.
* filename, a wildcard, or some portion of a file name

ie.

AddIcon (Image,/icons/image3.gif) .gif .jpg .png

 

Other Options

 

IndexHeadInsert

# insert in the <head> section of the HTML generated for the index page.

IndexHeadInsert "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />"

IndexIgnore

# Multiple IndexIgnore directives add to the list
# shell-style wildcard expression

IndexIgnore .htaccess /theme

 

Header 與 Footer

 

# taken to be relative to the location being indexed
HeaderName HEADER.html
ReadmeName FOOTER.html

 

不錯的 icon 包 (Apache Autoindex Theme)

 

[1] Apaxy (http://adamwhitcroft.com/apaxy/)

1. Copy and paste the contents of the /apaxy folder to your /share folder.

cd SHARE_PATH

wget https://github.com/AdamWhitcroft/Apaxy/archive/master.zip

unzip master.zip

mv Apaxy-master/apaxy/* ./

2. modify "htaccess.txt" *{FOLDERNAME}* to point to your "Site root" (http://xxxx)

i.e. http://tools.datahunter.org

:%s/\/{FOLDERNAME}/http:\/\/YOUR_DOMAIN/g

P.S.

如果不想比人知那層有咩 file, 就可以

touch index.html

3. htaccess.txt to .htaccess

mv htaccess.txt .htaccess

 

[2] https://github.com/unu/autoindex-style

用 .htaccess 的 ReadmeName 去 load .autoindex.html

.autoindex.html 內儲存了 icon ("data:image/png;base64,iVBORw...")

 

[3] - ABBA · Apache Bootstrap & Bootswatch Autoindex

https://github.com/jmlemetayer/abba

Enable Server Side Includes

a2enmod include

Easy installing

T=$(mktemp) && curl -sL git.io/abba -o $T && sh $T

 


 

Creative Commons license icon Creative Commons license icon