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
|
# handle username-based prefix subpaths of the form "subpath@url?" or "__?@__"
|
17
|
# supports multiple @ , nested . , & query str: a@b.c@url?@.d&q -> url?b.c.a.d&q
|
18
|
# ( @ is effectively a placeholder for the decoded username prefix)
|
19
|
# better than subpath.host because case is preserved and special chars allowed
|
20
|
# must require trailing ? , to avoid needing login to view the page itself
|
21
|
# must come before other redirects, because they lose the username
|
22
|
RewriteCond %{THE_REQUEST} "\? \S+$" [ornext]
|
23
|
RewriteCond %{QUERY_STRING} ^@
|
24
|
RewriteRule ^ username_prefix.php [discardpath,last,noescape,qsappend]
|
25
|
|
26
|
# remove www subdomain
|
27
|
RewriteCond %{HTTP_HOST} ^www\.(.*)$
|
28
|
RewriteRule ^.*$ %{REQUEST_SCHEME}://%1%{REQUEST_URI} [discardpath,last,noescape,qsappend]
|
29
|
|
30
|
# remove linewraps used to create a newline for Google spreadsheets
|
31
|
RewriteRule ^_-(.*)$ /$1 [discardpath,last,noescape,qsappend,redirect]
|
32
|
|
33
|
## translate subdomain to path
|
34
|
# set REQUEST_URI_no_extra_/
|
35
|
RewriteCond %{REQUEST_URI} ^(?:/|(.*))$
|
36
|
RewriteRule ^ - [env=REQUEST_URI_no_extra_/:%1]
|
37
|
# translate
|
38
|
RewriteCond %{HTTP_HOST} !=vegbiendev.nceas.ucsb.edu
|
39
|
RewriteCond %{HTTP_HOST} ^(.*)\.([^.]*\.[^.]*)$
|
40
|
RewriteRule ^.*$ %{REQUEST_SCHEME}://%2/${subdomain2path:%1}%{ENV:REQUEST_URI_no_extra_/} [discardpath,last,noescape,qsappend]
|
41
|
|
42
|
# use separate lowercase version when available
|
43
|
RewriteCond %{ENV:innermost_dir} =/
|
44
|
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
|
45
|
RewriteCond .${tolower:$1} ^.*$
|
46
|
RewriteCond %{DOCUMENT_ROOT}/%0 -d
|
47
|
RewriteRule ^([^/]*)(.*)$ %0$2 [discardpath,last,noescape,qsappend]
|
48
|
# last: rewrite in the new subdir instead of applying this dir's rules
|
49
|
|
50
|
# auto-detect dotpath in query string (having a . or & before any = )
|
51
|
# you can prepend . to force a dotpath, or & to force a query param
|
52
|
RewriteCond %{QUERY_STRING} ^(?![.&]).+$
|
53
|
# . not already prepended, does not start with & , and non-empty
|
54
|
RewriteCond %{QUERY_STRING} ^[^=]*(?:[.&]|$)
|
55
|
# . or & before any =
|
56
|
RewriteRule ^.*$ $0?.%{QUERY_STRING} [discardpath,noescape]
|
57
|
|
58
|
## parse dotpath in query string
|
59
|
# make dotpath replacement start with ./ instead of /
|
60
|
RewriteCond %{QUERY_STRING} ^\.
|
61
|
RewriteRule ^$ . [discardpath,noescape,qsappend]
|
62
|
# parse dotpath levels repeatedly in QUERY_STRING
|
63
|
RewriteCond %{QUERY_STRING} ^\.([^./&]*?)(?:\[([^\[\]/&]*)\])?([.&].*)?$
|
64
|
RewriteRule ^(.*?)(?:/(?:index(?:\.\w+)?)?)?$ $1/%1%2?%3 [discardpath,noescape,next,env=needs_redirect:1]
|
65
|
# redirect so REQUEST_URI is populated from REQUEST_FILENAME
|
66
|
RewriteCond %{ENV:needs_redirect} !=""
|
67
|
RewriteRule ^ - [discardpath,last,noescape,qsappend,redirect]
|
68
|
# - uses REQUEST_FILENAME as redirect dest instead of empty REQUEST_URI
|
69
|
|
70
|
# <dir>/all forces mod_autoindex listing
|
71
|
RewriteRule ^(.*/)?all$ $1 [discardpath,last,noescape,qsappend,env=mod_autoindex_listing:1]
|
72
|
|
73
|
# for dirs, redirect to index.* unless mod_autoindex listing was requested
|
74
|
# can't use "index" b/c MultiViews doesn't support that filename in Ubuntu 14.04
|
75
|
RewriteCond %{REQUEST_FILENAME}index.php -F
|
76
|
# use -F subrequest so that MultiViews auto-appends any extension
|
77
|
RewriteCond %{ENV:REDIRECT_mod_autoindex_listing} =""
|
78
|
RewriteRule ^(.*/)?$ $1index.php [discardpath,last,noescape,qsappend]
|
79
|
RewriteCond %{REQUEST_FILENAME}index.htm -F
|
80
|
# use -F subrequest so that MultiViews auto-appends any extension
|
81
|
RewriteCond %{ENV:REDIRECT_mod_autoindex_listing} =""
|
82
|
RewriteRule ^(.*/)?$ $1index.htm [discardpath,last,noescape,qsappend]
|
83
|
|
84
|
# don't rewrite existing dirs with trailing /
|
85
|
RewriteCond %{REQUEST_FILENAME} -d
|
86
|
RewriteRule ^.+/$ - [discardpath,last,noescape,qsappend]
|
87
|
|
88
|
# don't rewrite existing files
|
89
|
RewriteCond %{REQUEST_FILENAME} -f
|
90
|
RewriteRule ^.+$ - [discardpath,last,noescape,qsappend]
|
91
|
|
92
|
# auto-add trailing / unless has an .htaccess with possible redirect
|
93
|
RewriteCond %{REQUEST_FILENAME} -d
|
94
|
RewriteCond %{REQUEST_FILENAME}/.htaccess !-f
|
95
|
RewriteRule ^.+$ %{REQUEST_URI}/ [discardpath,last,noescape,qsappend,redirect]
|
96
|
|
97
|
# prepend dir name if it's part of the filename (e.g. dir/file -> dir/dir.file)
|
98
|
# works only if dir supports relative redirects and sets %{ENV:innermost_dir}
|
99
|
RewriteCond %{REQUEST_FILENAME} ^(.*/)?(.+?)$
|
100
|
RewriteCond %1%{ENV:innermost_dir}.%2 -F
|
101
|
RewriteRule ^(?!/)(.*/)?(.+?)$ $1%{ENV:innermost_dir}.$2 [discardpath,last,noescape,qsappend,redirect]
|
102
|
|
103
|
## specific to /
|
104
|
|
105
|
RewriteCond %{ENV:innermost_dir} =/
|
106
|
RewriteRule ^.+$ /VegCore/$0 [discardpath,last,noescape,qsappend]
|
107
|
|
108
|
|
109
|
#### directory indexing
|
110
|
|
111
|
### mod_autoindex
|
112
|
|
113
|
IndexOptions +FoldersFirst +HTMLTable +IconsAreLinks +IgnoreCase +TrackModified +VersionSort +XHTML
|
114
|
IndexOrderDefault Ascending Description
|
115
|
|
116
|
IndexStyleSheet /main.css
|
117
|
IndexHeadInsert '<div><i>Note that some listed files are not web-accessible. They will produce a "Forbidden" error when clicked.</i></div>'
|
118
|
|
119
|
IndexIgnoreReset on
|
120
|
IndexIgnore .svn
|