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