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 . before any = )
49
# you can prepend . to force a dotpath, or & to force a query param
50
RewriteCond %{QUERY_STRING} ^(?!\.)[^&]+$
51
RewriteCond %0 ^[^=]*(?:\.|$)
52
RewriteRule ^.*$ $0?.%{QUERY_STRING} [discardpath,noescape]
53

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

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

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

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

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

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

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

    
99
## specific to /
100

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

    
104

    
105
#### directory indexing
106

    
107
### mod_autoindex
108

    
109
IndexOptions +FoldersFirst +HTMLTable +IconsAreLinks +IgnoreCase +TrackModified +VersionSort +XHTML
110
IndexOrderDefault Ascending Description
111

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

    
115
IndexIgnoreReset on
116
IndexIgnore .svn
(8-8/35)