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