Project

General

Profile

1 7876 aaronmk
#### URL resolution
2
3 8397 aaronmk
Options +FollowSymLinks +Indexes +MultiViews
4 8055 aaronmk
5 8402 aaronmk
DirectorySlash off
6 8396 aaronmk
DirectoryIndex index
7 7876 aaronmk
8
### mod_rewrite
9
10 7878 aaronmk
RewriteEngine on
11 8405 aaronmk
RewriteOptions AllowNoSlash
12 7876 aaronmk
13 8443 aaronmk
SetEnvIf Request_URI ^ innermost_dir=/
14
15 7959 aaronmk
# remove www subdomain
16
RewriteCond %{HTTP_HOST} ^www\.(.*)$
17 8507 aaronmk
RewriteRule ^.*$ %{REQUEST_SCHEME}://%1%{REQUEST_URI} [discardpath,last,noescape,qsappend]
18 7959 aaronmk
19 8178 aaronmk
# remove linewraps used to create a newline for Google spreadsheets
20 8507 aaronmk
RewriteRule ^_-(.*)$ /$1 [discardpath,last,noescape,qsappend,redirect]
21 8178 aaronmk
22 8503 aaronmk
## translate subdomain to path
23 8504 aaronmk
# set REQUEST_URI_no_extra_/
24 8502 aaronmk
RewriteCond %{REQUEST_URI} ^(?:/|(.*))$
25 8504 aaronmk
RewriteRule ^ - [env=REQUEST_URI_no_extra_/:%1]
26 8503 aaronmk
# translate
27 8022 aaronmk
RewriteCond %{HTTP_HOST} !=vegbiendev.nceas.ucsb.edu
28
RewriteCond %{HTTP_HOST} ^(.*)\.([^.]*\.[^.]*)$
29 8507 aaronmk
RewriteRule ^.*$ %{REQUEST_SCHEME}://%2/${subdomain2path:%1}%{ENV:REQUEST_URI_no_extra_/} [discardpath,last,noescape,qsappend]
30 7987 aaronmk
31 8035 aaronmk
# use separate lowercase version when available
32 8443 aaronmk
RewriteCond %{ENV:innermost_dir} =/
33 8035 aaronmk
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
34 8058 aaronmk
RewriteCond .${tolower:$1} ^.*$
35 8057 aaronmk
RewriteCond %{DOCUMENT_ROOT}/%0 -d
36 8507 aaronmk
RewriteRule ^([^/]*)(.*)$ %0$2 [discardpath,last,noescape,qsappend]
37 8389 aaronmk
	# last: rewrite in the new subdir instead of applying this dir's rules
38 8035 aaronmk
39 8500 aaronmk
# 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 8505 aaronmk
## parse dotpath in query string
46
# parse dotpath levels repeatedly in QUERY_STRING
47
RewriteCond %{QUERY_STRING} ^\.([^./&]*?)(?:\[([^\[\]/&]*)\])?([.&].*)?$
48
RewriteRule ^(.*?)(?:/(?:index(?:\.\w+)?)?)?$ $1/%1%2?%3 [discardpath,noescape,next,env=needs_redirect:1]
49
# redirect so REQUEST_URI is populated from REQUEST_FILENAME
50
RewriteCond %{ENV:needs_redirect} !=""
51
RewriteRule ^.*$ $0 [last,redirect]
52 7997 aaronmk
53 8481 aaronmk
# don't rewrite existing dirs with trailing /
54
RewriteCond %{REQUEST_FILENAME} -d
55 8507 aaronmk
RewriteRule ^.+/$ - [discardpath,last,noescape,qsappend]
56 8481 aaronmk
57
# don't rewrite existing files
58 8363 aaronmk
RewriteCond %{REQUEST_FILENAME} -f
59 8507 aaronmk
RewriteRule ^.+$ - [discardpath,last,noescape,qsappend]
60 8041 aaronmk
61 8483 aaronmk
# auto-add trailing / unless has an .htaccess with possible redirect
62
RewriteCond %{REQUEST_FILENAME} -d
63
RewriteCond %{REQUEST_FILENAME}/.htaccess !-f
64 8507 aaronmk
RewriteRule ^.+$ %{REQUEST_URI}/ [discardpath,last,noescape,qsappend,redirect]
65 8482 aaronmk
66 8447 aaronmk
# handle DirectoryIndex subrequests when there is no DirectoryIndex
67
# use -F subrequest so that MultiViews auto-appends any extension
68
RewriteCond %{REQUEST_FILENAME} !-F
69 8450 aaronmk
RewriteRule ^(.*/)?index$ $1 [discardpath,noescape,qsappend]
70 8447 aaronmk
71 8496 aaronmk
# prepend dir name if it's part of the filename (e.g. dir/file -> dir/dir.file)
72
# works only if dir supports relative redirects and sets %{ENV:innermost_dir}
73
RewriteCond %{REQUEST_FILENAME} ^(.*/)?(.+?)$
74 8498 aaronmk
RewriteCond %1%{ENV:innermost_dir}.%2 -F
75 8507 aaronmk
RewriteRule ^(?!/)(.*/)?(.+?)$ $1%{ENV:innermost_dir}.$2 [discardpath,last,noescape,qsappend,redirect]
76 8496 aaronmk
77 8041 aaronmk
## specific to /
78
79 8443 aaronmk
RewriteCond %{ENV:innermost_dir} =/
80 8507 aaronmk
RewriteRule ^.+$ /VegCore/$0 [discardpath,last,noescape,qsappend]