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
|
# set REQUEST_URI_NO_SLASH
|
23
|
RewriteCond %{REQUEST_URI} ^/$ [ornext]
|
24
|
RewriteCond %{REQUEST_URI} ^(.*)$
|
25
|
RewriteRule ^ - [env=REQUEST_URI_no_/:%1]
|
26
|
|
27
|
# translate subdomain to path
|
28
|
RewriteCond %{HTTP_HOST} !=vegbiendev.nceas.ucsb.edu
|
29
|
RewriteCond %{HTTP_HOST} ^(.*)\.([^.]*\.[^.]*)$
|
30
|
RewriteRule ^.*$ %{REQUEST_SCHEME}://%2/${subdomain2path:%1}%{ENV:REQUEST_URI_no_/} [discardpath,noescape,last,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,noescape,last,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 (having a . before any = )
|
47
|
# you can prepend . to force a dotpath, or & to force a query param
|
48
|
RewriteRule ^dotpath - [discardpath,noescape,last,qsappend]
|
49
|
RewriteCond %{QUERY_STRING} ^[^&]+
|
50
|
RewriteCond %0 ^[^=]*(?:\.|$)
|
51
|
RewriteCond %{REQUEST_URI} ^(.*?)(?:/index(?:\.\w+)?)?$
|
52
|
RewriteRule ^.*$ /dotpath%1 [discardpath,noescape,last,qsappend]
|
53
|
|
54
|
# don't rewrite existing dirs with trailing /
|
55
|
RewriteCond %{REQUEST_FILENAME} -d
|
56
|
RewriteRule ^.+/$ - [discardpath,noescape,last,qsappend]
|
57
|
|
58
|
# don't rewrite existing files
|
59
|
RewriteCond %{REQUEST_FILENAME} -f
|
60
|
RewriteRule ^.+$ - [discardpath,noescape,last,qsappend]
|
61
|
|
62
|
# auto-add trailing / unless has an .htaccess with possible redirect
|
63
|
RewriteCond %{REQUEST_FILENAME} -d
|
64
|
RewriteCond %{REQUEST_FILENAME}/.htaccess !-f
|
65
|
RewriteRule ^.+$ %{REQUEST_URI}/ [discardpath,noescape,last,redirect,qsappend]
|
66
|
|
67
|
# handle DirectoryIndex subrequests when there is no DirectoryIndex
|
68
|
# use -F subrequest so that MultiViews auto-appends any extension
|
69
|
RewriteCond %{REQUEST_FILENAME} !-F
|
70
|
RewriteRule ^(.*/)?index$ $1 [discardpath,noescape,qsappend]
|
71
|
|
72
|
# prepend dir name if it's part of the filename (e.g. dir/file -> dir/dir.file)
|
73
|
# works only if dir supports relative redirects and sets %{ENV:innermost_dir}
|
74
|
RewriteCond %{REQUEST_FILENAME} ^(.*/)?(.+?)$
|
75
|
RewriteCond %1%{ENV:innermost_dir}.%2 -F
|
76
|
RewriteRule ^(?!/)(.*/)?(.+?)$ $1%{ENV:innermost_dir}.$2 [discardpath,noescape,last,redirect,qsappend]
|
77
|
|
78
|
## specific to /
|
79
|
|
80
|
RewriteCond %{ENV:innermost_dir} =/
|
81
|
RewriteRule ^.+$ /VegCore/$0 [discardpath,noescape,last,qsappend]
|