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
# 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
# must come before username prefix parsing, because it requires the leading [.&]
19
RewriteCond %{QUERY_STRING} ^(?!@?[.&]).+$
20
	# [.&] not already prepended and non-empty
21
RewriteCond %{QUERY_STRING} ^@?[^=]*(?:[.&]|$)
22
	# . or & before any =
23
RewriteCond %{QUERY_STRING} ^(@?)(.*)$
24
RewriteRule ^.*$ $0?%1.%2 [discardpath,noescape]
25
# 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

    
31
# handle username-based prefix subpaths of the form "subpath@host//path"
32
# supports multiple @ , nested . , & query str: a@b.c@url//?d&q -> url?b.c.a.d&q
33
# better than subpath.host because case is preserved and special chars allowed
34
# must require leading // , to avoid needing login to view the page itself
35
# must come before external redirects, because they lose the username
36
RewriteCond %{THE_REQUEST} "\S+ //"
37
RewriteRule ^ username_prefix.php [discardpath,last,noescape,qsappend]
38

    
39
# remove www subdomain
40
RewriteCond %{HTTP_HOST} ^www\.(.*)$
41
RewriteRule ^.*$ %{REQUEST_SCHEME}://%1%{REQUEST_URI} [discardpath,last,noescape,qsappend]
42

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

    
46
## translate subdomain to path
47
# set REQUEST_URI_no_extra_/
48
RewriteCond %{REQUEST_URI} ^(?:/|(.*))$
49
RewriteRule ^ - [env=REQUEST_URI_no_extra_/:%1]
50
# translate
51
RewriteCond %{HTTP_HOST} !=vegbiendev.nceas.ucsb.edu
52
RewriteCond %{HTTP_HOST} ^(.*)\.([^.]+\.[^.]+)\.?$
53
RewriteRule ^.*$ %{REQUEST_SCHEME}://%2/${subdomain2path:%1}%{ENV:REQUEST_URI_no_extra_/} [discardpath,last,noescape,qsappend]
54

    
55
# use separate lowercase version when available
56
RewriteCond %{ENV:innermost_dir} =/
57
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
58
RewriteCond .${tolower:$1} ^.*$
59
RewriteCond %{DOCUMENT_ROOT}/%0 -d
60
RewriteRule ^([^/]*)(.*)$ %0$2 [discardpath,last,noescape,qsappend]
61
	# last: rewrite in the new subdir instead of applying this dir's rules
62

    
63
## parse dotpath in query string
64
# make dotpath replacement start with ./ instead of /
65
RewriteCond %{QUERY_STRING} ^\.
66
RewriteRule ^$ . [discardpath,noescape,qsappend]
67
# parse dotpath levels repeatedly in QUERY_STRING
68
RewriteCond %{QUERY_STRING} ^\.([^./&]*?)(?:\[([^\[\]/&]*)\])?([.&].*)?$
69
RewriteRule ^(.*?)(?:/(?:index(?:\.\w+)?)?)?$ $1/%1%2?%3 [discardpath,noescape,next,env=needs_redirect:1]
70
# redirect so REQUEST_URI is populated from REQUEST_FILENAME
71
RewriteCond %{ENV:needs_redirect} !=""
72
RewriteRule ^ - [discardpath,last,noescape,qsappend,redirect]
73
	# - uses REQUEST_FILENAME as redirect dest instead of empty REQUEST_URI
74

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

    
78
# for dirs, redirect to index.* unless mod_autoindex listing was requested
79
# can't use "index" b/c MultiViews doesn't support that filename in Ubuntu 14.04
80
RewriteCond %{REQUEST_FILENAME}index.php -F
81
	# use -F subrequest so that MultiViews auto-appends any extension
82
RewriteCond %{ENV:REDIRECT_mod_autoindex_listing} =""
83
RewriteRule ^(.*/)?$ $1index.php [discardpath,last,noescape,qsappend]
84
RewriteCond %{REQUEST_FILENAME}index.htm -F
85
	# use -F subrequest so that MultiViews auto-appends any extension
86
RewriteCond %{ENV:REDIRECT_mod_autoindex_listing} =""
87
RewriteRule ^(.*/)?$ $1index.htm [discardpath,last,noescape,qsappend]
88

    
89
# don't rewrite existing dirs with trailing /
90
RewriteCond %{REQUEST_FILENAME} -d
91
RewriteRule ^.+/$ - [discardpath,last,noescape,qsappend]
92

    
93
# don't rewrite existing files
94
RewriteCond %{REQUEST_FILENAME} -f
95
RewriteRule ^.+$ - [discardpath,last,noescape,qsappend]
96

    
97
# auto-add trailing / unless has an .htaccess with possible redirect
98
RewriteCond %{REQUEST_FILENAME} -d
99
RewriteCond %{REQUEST_FILENAME}/.htaccess !-f
100
RewriteRule ^.+$ %{REQUEST_URI}/ [discardpath,last,noescape,qsappend,redirect]
101

    
102
# prepend dir name if it's part of the filename (e.g. dir/file -> dir/dir.file)
103
# works only if dir supports relative redirects and sets %{ENV:innermost_dir}
104
RewriteCond %{REQUEST_FILENAME} ^(.*/)?(.+?)$
105
RewriteCond %1%{ENV:innermost_dir}.%2 -F
106
RewriteRule ^(?!/)(.*/)?(.+?)$ $1%{ENV:innermost_dir}.$2 [discardpath,last,noescape,qsappend,redirect]
107

    
108
## specific to /
109

    
110
RewriteCond %{ENV:innermost_dir} =/
111
RewriteRule ^.+$ /VegCore/$0 [discardpath,last,noescape,qsappend]
112

    
113

    
114
#### directory indexing
115

    
116
### mod_autoindex
117

    
118
IndexOptions +FoldersFirst +HTMLTable +IconsAreLinks +IgnoreCase +TrackModified +VersionSort +XHTML
119
IndexOrderDefault Ascending Description
120

    
121
IndexStyleSheet /main.css
122
IndexHeadInsert '<div><i>Note that some listed files are not web-accessible. They will produce a "Forbidden" error when clicked.</i></div>'
123

    
124
IndexIgnoreReset on
125
IndexIgnore .svn
(8-8/35)