Project

General

Profile

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 13617 aaronmk
# 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 13615 aaronmk
# 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 13617 aaronmk
RewriteCond %{THE_REQUEST} "[?&] \S+$"
22 13615 aaronmk
RewriteRule ^ username_prefix.php [discardpath,last,noescape,qsappend]
23
24 7959 aaronmk
# remove www subdomain
25
RewriteCond %{HTTP_HOST} ^www\.(.*)$
26 8507 aaronmk
RewriteRule ^.*$ %{REQUEST_SCHEME}://%1%{REQUEST_URI} [discardpath,last,noescape,qsappend]
27 7959 aaronmk
28 8178 aaronmk
# remove linewraps used to create a newline for Google spreadsheets
29 8507 aaronmk
RewriteRule ^_-(.*)$ /$1 [discardpath,last,noescape,qsappend,redirect]
30 8178 aaronmk
31 8503 aaronmk
## translate subdomain to path
32 8504 aaronmk
# set REQUEST_URI_no_extra_/
33 8502 aaronmk
RewriteCond %{REQUEST_URI} ^(?:/|(.*))$
34 8504 aaronmk
RewriteRule ^ - [env=REQUEST_URI_no_extra_/:%1]
35 8503 aaronmk
# translate
36 8022 aaronmk
RewriteCond %{HTTP_HOST} !=vegbiendev.nceas.ucsb.edu
37
RewriteCond %{HTTP_HOST} ^(.*)\.([^.]*\.[^.]*)$
38 8507 aaronmk
RewriteRule ^.*$ %{REQUEST_SCHEME}://%2/${subdomain2path:%1}%{ENV:REQUEST_URI_no_extra_/} [discardpath,last,noescape,qsappend]
39 7987 aaronmk
40 8035 aaronmk
# use separate lowercase version when available
41 8443 aaronmk
RewriteCond %{ENV:innermost_dir} =/
42 8035 aaronmk
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
43 8058 aaronmk
RewriteCond .${tolower:$1} ^.*$
44 8057 aaronmk
RewriteCond %{DOCUMENT_ROOT}/%0 -d
45 8507 aaronmk
RewriteRule ^([^/]*)(.*)$ %0$2 [discardpath,last,noescape,qsappend]
46 8389 aaronmk
	# last: rewrite in the new subdir instead of applying this dir's rules
47 8035 aaronmk
48 8500 aaronmk
# 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 10669 aaronmk
RewriteCond %{QUERY_STRING} ^(?!\.)[^&]+$
51 8500 aaronmk
RewriteCond %0 ^[^=]*(?:\.|$)
52 10670 aaronmk
RewriteRule ^.*$ $0?.%{QUERY_STRING} [discardpath,noescape]
53 8500 aaronmk
54 8505 aaronmk
## parse dotpath in query string
55 10612 aaronmk
# make dotpath replacement start with ./ instead of /
56
RewriteCond %{QUERY_STRING} ^\.
57
RewriteRule ^$ . [discardpath,noescape,qsappend]
58 8505 aaronmk
# 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 10611 aaronmk
RewriteRule ^ - [discardpath,last,noescape,qsappend,redirect]
64
	# - uses REQUEST_FILENAME as redirect dest instead of empty REQUEST_URI
65 7997 aaronmk
66 9612 aaronmk
# <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 13306 aaronmk
# can't use "index" b/c MultiViews doesn't support that filename in Ubuntu 14.04
71 13304 aaronmk
RewriteCond %{REQUEST_FILENAME}index.php -F
72 9612 aaronmk
	# use -F subrequest so that MultiViews auto-appends any extension
73
RewriteCond %{ENV:REDIRECT_mod_autoindex_listing} =""
74 13304 aaronmk
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 9612 aaronmk
80 8481 aaronmk
# don't rewrite existing dirs with trailing /
81
RewriteCond %{REQUEST_FILENAME} -d
82 8507 aaronmk
RewriteRule ^.+/$ - [discardpath,last,noescape,qsappend]
83 8481 aaronmk
84
# don't rewrite existing files
85 8363 aaronmk
RewriteCond %{REQUEST_FILENAME} -f
86 8507 aaronmk
RewriteRule ^.+$ - [discardpath,last,noescape,qsappend]
87 8041 aaronmk
88 8483 aaronmk
# auto-add trailing / unless has an .htaccess with possible redirect
89
RewriteCond %{REQUEST_FILENAME} -d
90
RewriteCond %{REQUEST_FILENAME}/.htaccess !-f
91 8507 aaronmk
RewriteRule ^.+$ %{REQUEST_URI}/ [discardpath,last,noescape,qsappend,redirect]
92 8482 aaronmk
93 8496 aaronmk
# 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 8498 aaronmk
RewriteCond %1%{ENV:innermost_dir}.%2 -F
97 8507 aaronmk
RewriteRule ^(?!/)(.*/)?(.+?)$ $1%{ENV:innermost_dir}.$2 [discardpath,last,noescape,qsappend,redirect]
98 8496 aaronmk
99 8041 aaronmk
## specific to /
100
101 8443 aaronmk
RewriteCond %{ENV:innermost_dir} =/
102 8507 aaronmk
RewriteRule ^.+$ /VegCore/$0 [discardpath,last,noescape,qsappend]
103 9604 aaronmk
104
105
#### directory indexing
106
107
### mod_autoindex
108
109 11034 aaronmk
IndexOptions +FoldersFirst +HTMLTable +IconsAreLinks +IgnoreCase +TrackModified +VersionSort +XHTML
110 9609 aaronmk
IndexOrderDefault Ascending Description
111 9608 aaronmk
112 11039 aaronmk
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 11649 aaronmk
115
IndexIgnoreReset on
116
IndexIgnore .svn