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