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