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