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
# handle username-based prefix subpaths of the form "subpath@url?" or "__?__&"
17
# supports multiple @ , nested . , & query str: a@b.c@url?k=v& -> url?b.c.a&k=v
18
# better than subpath.host because case is preserved and special chars allowed
19
# must require trailing ? , to avoid needing login to view the page itself
20
# must come before other redirects, because they lose the username
21
RewriteCond %{THE_REQUEST} "[?&] \S+$"
22
RewriteRule ^ username_prefix.php [discardpath,last,noescape,qsappend]
23

    
24
# remove www subdomain
25
RewriteCond %{HTTP_HOST} ^www\.(.*)$
26
RewriteRule ^.*$ %{REQUEST_SCHEME}://%1%{REQUEST_URI} [discardpath,last,noescape,qsappend]
27

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

    
31
## translate subdomain to path
32
# set REQUEST_URI_no_extra_/
33
RewriteCond %{REQUEST_URI} ^(?:/|(.*))$
34
RewriteRule ^ - [env=REQUEST_URI_no_extra_/:%1]
35
# translate
36
RewriteCond %{HTTP_HOST} !=vegbiendev.nceas.ucsb.edu
37
RewriteCond %{HTTP_HOST} ^(.*)\.([^.]*\.[^.]*)$
38
RewriteRule ^.*$ %{REQUEST_SCHEME}://%2/${subdomain2path:%1}%{ENV:REQUEST_URI_no_extra_/} [discardpath,last,noescape,qsappend]
39

    
40
# use separate lowercase version when available
41
RewriteCond %{ENV:innermost_dir} =/
42
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
43
RewriteCond .${tolower:$1} ^.*$
44
RewriteCond %{DOCUMENT_ROOT}/%0 -d
45
RewriteRule ^([^/]*)(.*)$ %0$2 [discardpath,last,noescape,qsappend]
46
	# last: rewrite in the new subdir instead of applying this dir's rules
47

    
48
# auto-detect dotpath in query string (having a . or & before any = )
49
# you can prepend . to force a dotpath, or & to force a query param
50
RewriteCond %{QUERY_STRING} ^(?![.&]).+$
51
	# . not already prepended, does not start with & , and non-empty
52
RewriteCond %{QUERY_STRING} ^[^=]*(?:[.&]|$)
53
	# . or & before any =
54
RewriteRule ^.*$ $0?.%{QUERY_STRING} [discardpath,noescape]
55

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

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

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

    
82
# don't rewrite existing dirs with trailing /
83
RewriteCond %{REQUEST_FILENAME} -d
84
RewriteRule ^.+/$ - [discardpath,last,noescape,qsappend]
85

    
86
# don't rewrite existing files
87
RewriteCond %{REQUEST_FILENAME} -f
88
RewriteRule ^.+$ - [discardpath,last,noescape,qsappend]
89

    
90
# auto-add trailing / unless has an .htaccess with possible redirect
91
RewriteCond %{REQUEST_FILENAME} -d
92
RewriteCond %{REQUEST_FILENAME}/.htaccess !-f
93
RewriteRule ^.+$ %{REQUEST_URI}/ [discardpath,last,noescape,qsappend,redirect]
94

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

    
101
## specific to /
102

    
103
RewriteCond %{ENV:innermost_dir} =/
104
RewriteRule ^.+$ /VegCore/$0 [discardpath,last,noescape,qsappend]
105

    
106

    
107
#### directory indexing
108

    
109
### mod_autoindex
110

    
111
IndexOptions +FoldersFirst +HTMLTable +IconsAreLinks +IgnoreCase +TrackModified +VersionSort +XHTML
112
IndexOrderDefault Ascending Description
113

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

    
117
IndexIgnoreReset on
118
IndexIgnore .svn
(8-8/35)