1
|
#### URL resolution
|
2
|
|
3
|
Options +FollowSymLinks +Indexes +MultiViews
|
4
|
|
5
|
DirectorySlash off
|
6
|
DirectoryIndex index
|
7
|
|
8
|
### mod_rewrite
|
9
|
|
10
|
RewriteEngine on
|
11
|
RewriteOptions AllowNoSlash
|
12
|
|
13
|
SetEnvIf Request_URI ^ innermost_dir=/
|
14
|
|
15
|
# remove www subdomain
|
16
|
RewriteCond %{HTTP_HOST} ^www\.(.*)$
|
17
|
RewriteRule ^.*$ %{REQUEST_SCHEME}://%1%{REQUEST_URI} [discardpath,noescape,last,qsappend]
|
18
|
|
19
|
# remove linewraps used to create a newline for Google spreadsheets
|
20
|
RewriteRule ^_-(.*)$ /$1 [discardpath,noescape,last,redirect,qsappend]
|
21
|
|
22
|
## translate subdomain to path
|
23
|
# set REQUEST_URI_no_extra_/
|
24
|
RewriteCond %{REQUEST_URI} ^(?:/|(.*))$
|
25
|
RewriteRule ^ - [env=REQUEST_URI_no_extra_/:%1]
|
26
|
# translate
|
27
|
RewriteCond %{HTTP_HOST} !=vegbiendev.nceas.ucsb.edu
|
28
|
RewriteCond %{HTTP_HOST} ^(.*)\.([^.]*\.[^.]*)$
|
29
|
RewriteRule ^.*$ %{REQUEST_SCHEME}://%2/${subdomain2path:%1}%{ENV:REQUEST_URI_no_extra_/} [discardpath,noescape,last,qsappend]
|
30
|
|
31
|
# use separate lowercase version when available
|
32
|
RewriteCond %{ENV:innermost_dir} =/
|
33
|
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
|
34
|
RewriteCond .${tolower:$1} ^.*$
|
35
|
RewriteCond %{DOCUMENT_ROOT}/%0 -d
|
36
|
RewriteRule ^([^/]*)(.*)$ %0$2 [discardpath,noescape,last,qsappend]
|
37
|
# last: rewrite in the new subdir instead of applying this dir's rules
|
38
|
|
39
|
# auto-detect dotpath in query string (having a . before any = )
|
40
|
# you can prepend . to force a dotpath, or & to force a query param
|
41
|
RewriteCond %{QUERY_STRING} ^(?!\.)[^&]+
|
42
|
RewriteCond %0 ^[^=]*(?:\.|$)
|
43
|
RewriteRule ^ ?.%{QUERY_STRING} [discardpath,noescape]
|
44
|
|
45
|
# parse dotpath in query string
|
46
|
RewriteRule ^dotpath - [discardpath,noescape,last,qsappend]
|
47
|
RewriteCond %{QUERY_STRING} ^\.
|
48
|
RewriteCond %{REQUEST_URI} ^(.*?)(?:/index(?:\.\w+)?)?$
|
49
|
RewriteRule ^.*$ /dotpath%1 [discardpath,noescape,last,qsappend]
|
50
|
|
51
|
# don't rewrite existing dirs with trailing /
|
52
|
RewriteCond %{REQUEST_FILENAME} -d
|
53
|
RewriteRule ^.+/$ - [discardpath,noescape,last,qsappend]
|
54
|
|
55
|
# don't rewrite existing files
|
56
|
RewriteCond %{REQUEST_FILENAME} -f
|
57
|
RewriteRule ^.+$ - [discardpath,noescape,last,qsappend]
|
58
|
|
59
|
# auto-add trailing / unless has an .htaccess with possible redirect
|
60
|
RewriteCond %{REQUEST_FILENAME} -d
|
61
|
RewriteCond %{REQUEST_FILENAME}/.htaccess !-f
|
62
|
RewriteRule ^.+$ %{REQUEST_URI}/ [discardpath,noescape,last,redirect,qsappend]
|
63
|
|
64
|
# handle DirectoryIndex subrequests when there is no DirectoryIndex
|
65
|
# use -F subrequest so that MultiViews auto-appends any extension
|
66
|
RewriteCond %{REQUEST_FILENAME} !-F
|
67
|
RewriteRule ^(.*/)?index$ $1 [discardpath,noescape,qsappend]
|
68
|
|
69
|
# prepend dir name if it's part of the filename (e.g. dir/file -> dir/dir.file)
|
70
|
# works only if dir supports relative redirects and sets %{ENV:innermost_dir}
|
71
|
RewriteCond %{REQUEST_FILENAME} ^(.*/)?(.+?)$
|
72
|
RewriteCond %1%{ENV:innermost_dir}.%2 -F
|
73
|
RewriteRule ^(?!/)(.*/)?(.+?)$ $1%{ENV:innermost_dir}.$2 [discardpath,noescape,last,redirect,qsappend]
|
74
|
|
75
|
## specific to /
|
76
|
|
77
|
RewriteCond %{ENV:innermost_dir} =/
|
78
|
RewriteRule ^.+$ /VegCore/$0 [discardpath,noescape,last,qsappend]
|