Project

General

Profile

1
#### URL resolution
2

    
3
Options +FollowSymLinks +Indexes +MultiViews
4

    
5
DirectorySlash off
6
DirectoryIndex disabled
7
	# index.* is instead supported by "redirect to index.*" RewriteRule
8

    
9
### mod_rewrite
10

    
11
RewriteEngine on
12
RewriteOptions AllowNoSlash
13

    
14
SetEnvIf Request_URI ^ innermost_dir=/
15

    
16
# 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
# 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
# must come before username prefix parsing, because it requires the leading [.&]
25
RewriteCond %{QUERY_STRING} ^(?![.&]).+$
26
	# [.&] not already prepended and non-empty
27
RewriteCond %{QUERY_STRING} ^[^=]*(?:[.&]|$)
28
	# . or & before any =
29
RewriteCond %{QUERY_STRING} ^.*$
30
RewriteRule ^.*$ $0?.%0 [discardpath,noescape,env=usernames_disabled:1]
31
# otherwise, prepend & to force a query param
32
RewriteCond %{QUERY_STRING} ^(?![.&]).+$
33
	# [.&] not already prepended and non-empty
34
RewriteCond %{QUERY_STRING} ^.*$
35
RewriteRule ^.*$ $0?&%0 [discardpath,noescape,env=usernames_disabled:1]
36

    
37
# 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
# better than subpath.host because case is preserved and special chars allowed
41
# **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
# must come before external redirects, because they lose the username
44
#
45
## doesn't have subdomain & host doesn't end in . (which disables usernames)
46
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
47
## doesn't have path (which disables usernames to avoid needing trailing . )
48
RewriteCond %{REQUEST_URI} =/
49
# original URL (if specified) also doesn't have path
50
RewriteCond %{REDIRECT_REQUEST_URI} ="" [ornext]
51
RewriteCond %{REDIRECT_REQUEST_URI} =/
52
## doesn't have query string (which disables usernames to avoid trailing . )
53
RewriteCond %{QUERY_STRING} =""
54
# another RewriteRule (possibly in a previous round) didn't turn off usernames
55
RewriteCond %{ENV:usernames_disabled} =""
56
RewriteCond %{ENV:REDIRECT_usernames_disabled} =""
57
RewriteRule ^.*$ username_prefix.php [discardpath,last,noescape,qsappend]
58

    
59
# remove www subdomain
60
RewriteCond %{HTTP_HOST} ^www\.(.*)$
61
RewriteRule ^.*$ %{REQUEST_SCHEME}://%1%{REQUEST_URI} [discardpath,last,noescape,qsappend]
62

    
63
# remove linewraps used to create a newline for Google spreadsheets
64
RewriteRule ^_-(.*)$ /$1 [discardpath,last,noescape,qsappend,redirect]
65

    
66
## translate subdomain to path
67
# set REQUEST_URI_no_extra_/
68
RewriteCond %{REQUEST_URI} ^(?:/|(.*))$
69
RewriteRule ^ - [env=REQUEST_URI_no_extra_/:%1]
70
# translate
71
RewriteCond %{HTTP_HOST} !=vegbiendev.nceas.ucsb.edu
72
RewriteCond %{HTTP_HOST} ^(.*)\.([^.]+\.[^.]+)\.?$
73
RewriteRule ^.*$ %{REQUEST_SCHEME}://%2/${subdomain2path:%1}%{ENV:REQUEST_URI_no_extra_/} [discardpath,last,noescape,qsappend]
74

    
75
# use separate lowercase version when available
76
RewriteCond %{ENV:innermost_dir} =/
77
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
78
RewriteCond .${tolower:$1} ^.*$
79
RewriteCond %{DOCUMENT_ROOT}/%0 -d
80
RewriteRule ^([^/]*)(.*)$ %0$2 [discardpath,last,noescape,qsappend]
81
	# last: rewrite in the new subdir instead of applying this dir's rules
82

    
83
## parse dotpath in query string
84
# make dotpath replacement start with ./ instead of /
85
RewriteCond %{QUERY_STRING} ^\.
86
RewriteRule ^$ . [discardpath,noescape,qsappend]
87
# 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
RewriteRule ^ - [discardpath,last,noescape,qsappend,redirect]
93
	# - uses REQUEST_FILENAME as redirect dest instead of empty REQUEST_URI
94

    
95
# <dir>/all forces mod_autoindex listing
96
RewriteRule ^(.*/)?all$ $1 [discardpath,last,noescape,qsappend,env=mod_autoindex_listing:1,env=usernames_disabled:1]
97

    
98
# for dirs, redirect to index.* unless mod_autoindex listing was requested
99
# can't use "index" b/c MultiViews doesn't support that filename in Ubuntu 14.04
100
RewriteCond %{REQUEST_FILENAME}index.php -F
101
	# use -F subrequest so that MultiViews auto-appends any extension
102
RewriteCond %{ENV:REDIRECT_mod_autoindex_listing} =""
103
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

    
109
# don't rewrite existing dirs with trailing /
110
RewriteCond %{ENV:ignore_fs} =""
111
RewriteCond %{REQUEST_FILENAME} -d
112
RewriteRule ^.+/$ - [discardpath,last,noescape,qsappend]
113

    
114
# don't rewrite existing files
115
RewriteCond %{ENV:ignore_fs} =""
116
RewriteCond %{REQUEST_FILENAME} -f
117
RewriteRule ^.+$ - [discardpath,last,noescape,qsappend]
118

    
119
# auto-add trailing / unless has an .htaccess with possible redirect
120
RewriteCond %{REQUEST_FILENAME} -d
121
RewriteCond %{REQUEST_FILENAME}/.htaccess !-f
122
RewriteRule ^.+$ %{REQUEST_URI}/ [discardpath,last,noescape,qsappend,redirect]
123

    
124
# 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
RewriteCond %1%{ENV:innermost_dir}.%2 -F
128
RewriteRule ^(?!/)(.*/)?(.+?)$ $1%{ENV:innermost_dir}.$2 [discardpath,last,noescape,qsappend,redirect]
129

    
130
## specific to /
131

    
132
RewriteCond %{ENV:innermost_dir} =/
133
RewriteRule ^.+$ /VegCore/$0 [discardpath,last,noescape,qsappend]
134

    
135

    
136
#### directory indexing
137

    
138
### mod_autoindex
139

    
140
IndexOptions +FoldersFirst +HTMLTable +IconsAreLinks +IgnoreCase +TrackModified +VersionSort +XHTML
141
IndexOrderDefault Ascending Description
142

    
143
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

    
146
IndexIgnoreReset on
147
IndexIgnore .svn
(8-8/36)