1
|
#### URL resolution
|
2
|
|
3
|
Options +FollowSymLinks +Indexes +MultiViews
|
4
|
|
5
|
DirectorySlash off
|
6
|
DirectoryIndex disabled
|
7
|
# index.* is instead supported by "redirect to index.*" RewriteRule
|
8
|
|
9
|
### mod_rewrite
|
10
|
|
11
|
RewriteEngine on
|
12
|
RewriteOptions AllowNoSlash
|
13
|
|
14
|
SetEnvIf Request_URI ^ innermost_dir=/
|
15
|
|
16
|
# remove www subdomain
|
17
|
RewriteCond %{HTTP_HOST} ^www\.(.*)$
|
18
|
RewriteRule ^.*$ %{REQUEST_SCHEME}://%1%{REQUEST_URI} [discardpath,last,noescape,qsappend]
|
19
|
|
20
|
# remove linewraps used to create a newline for Google spreadsheets
|
21
|
RewriteRule ^_-(.*)$ /$1 [discardpath,last,noescape,qsappend,redirect]
|
22
|
|
23
|
## translate subdomain to path
|
24
|
# set REQUEST_URI_no_extra_/
|
25
|
RewriteCond %{REQUEST_URI} ^(?:/|(.*))$
|
26
|
RewriteRule ^ - [env=REQUEST_URI_no_extra_/:%1]
|
27
|
# translate
|
28
|
RewriteCond %{HTTP_HOST} !=vegbiendev.nceas.ucsb.edu
|
29
|
RewriteCond %{HTTP_HOST} ^(.*)\.([^.]*\.[^.]*)$
|
30
|
RewriteRule ^.*$ %{REQUEST_SCHEME}://%2/${subdomain2path:%1}%{ENV:REQUEST_URI_no_extra_/} [discardpath,last,noescape,qsappend]
|
31
|
|
32
|
# use separate lowercase version when available
|
33
|
RewriteCond %{ENV:innermost_dir} =/
|
34
|
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
|
35
|
RewriteCond .${tolower:$1} ^.*$
|
36
|
RewriteCond %{DOCUMENT_ROOT}/%0 -d
|
37
|
RewriteRule ^([^/]*)(.*)$ %0$2 [discardpath,last,noescape,qsappend]
|
38
|
# last: rewrite in the new subdir instead of applying this dir's rules
|
39
|
|
40
|
# auto-detect dotpath in query string (having a . before any = )
|
41
|
# you can prepend . to force a dotpath, or & to force a query param
|
42
|
RewriteCond %{QUERY_STRING} ^(?!\.)[^&]+
|
43
|
RewriteCond %0 ^[^=]*(?:\.|$)
|
44
|
RewriteRule ^ ?.%{QUERY_STRING} [discardpath,noescape]
|
45
|
|
46
|
## parse dotpath in query string
|
47
|
# parse dotpath levels repeatedly in QUERY_STRING
|
48
|
RewriteCond %{QUERY_STRING} ^\.([^./&]*?)(?:\[([^\[\]/&]*)\])?([.&].*)?$
|
49
|
RewriteRule ^(.*?)(?:/(?:index(?:\.\w+)?)?)?$ $1/%1%2?%3 [discardpath,noescape,next,env=needs_redirect:1]
|
50
|
# redirect so REQUEST_URI is populated from REQUEST_FILENAME
|
51
|
RewriteCond %{ENV:needs_redirect} !=""
|
52
|
RewriteRule ^ - [discardpath,last,noescape,qsappend,redirect]
|
53
|
# - uses REQUEST_FILENAME as redirect dest instead of empty REQUEST_URI
|
54
|
|
55
|
# <dir>/all forces mod_autoindex listing
|
56
|
RewriteRule ^(.*/)?all$ $1 [discardpath,last,noescape,qsappend,env=mod_autoindex_listing:1]
|
57
|
|
58
|
# for dirs, redirect to index.* unless mod_autoindex listing was requested
|
59
|
RewriteCond %{REQUEST_FILENAME}index -F
|
60
|
# use -F subrequest so that MultiViews auto-appends any extension
|
61
|
RewriteCond %{ENV:REDIRECT_mod_autoindex_listing} =""
|
62
|
RewriteRule ^(.*/)?$ $1index [discardpath,last,noescape,qsappend]
|
63
|
|
64
|
# don't rewrite existing dirs with trailing /
|
65
|
RewriteCond %{REQUEST_FILENAME} -d
|
66
|
RewriteRule ^.+/$ - [discardpath,last,noescape,qsappend]
|
67
|
|
68
|
# don't rewrite existing files
|
69
|
RewriteCond %{REQUEST_FILENAME} -f
|
70
|
RewriteRule ^.+$ - [discardpath,last,noescape,qsappend]
|
71
|
|
72
|
# auto-add trailing / unless has an .htaccess with possible redirect
|
73
|
RewriteCond %{REQUEST_FILENAME} -d
|
74
|
RewriteCond %{REQUEST_FILENAME}/.htaccess !-f
|
75
|
RewriteRule ^.+$ %{REQUEST_URI}/ [discardpath,last,noescape,qsappend,redirect]
|
76
|
|
77
|
# prepend dir name if it's part of the filename (e.g. dir/file -> dir/dir.file)
|
78
|
# works only if dir supports relative redirects and sets %{ENV:innermost_dir}
|
79
|
RewriteCond %{REQUEST_FILENAME} ^(.*/)?(.+?)$
|
80
|
RewriteCond %1%{ENV:innermost_dir}.%2 -F
|
81
|
RewriteRule ^(?!/)(.*/)?(.+?)$ $1%{ENV:innermost_dir}.$2 [discardpath,last,noescape,qsappend,redirect]
|
82
|
|
83
|
## specific to /
|
84
|
|
85
|
RewriteCond %{ENV:innermost_dir} =/
|
86
|
RewriteRule ^.+$ /VegCore/$0 [discardpath,last,noescape,qsappend]
|
87
|
|
88
|
|
89
|
#### directory indexing
|
90
|
|
91
|
### mod_autoindex
|
92
|
|
93
|
IndexOptions +FoldersFirst +IconsAreLinks +IgnoreCase +TrackModified +VersionSort +XHTML
|
94
|
IndexOrderDefault Ascending Description
|
95
|
|
96
|
IndexHeadInsert '<link rel="stylesheet" type="text/css" href="/main.css" />\
|
97
|
<div><i>Note that some listed files are not web-accessible. They will produce a "Forbidden" error when clicked.</i></div>'
|