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