-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.htaccess
224 lines (167 loc) · 8.12 KB
/
.htaccess
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# This file is used when running with Apache. Adapted from web.config.
# NOTE: this is not very well tested...
php_value display_errors off
php_value display_startup_errors off
php_value include_path ".:/var/www/html/_includes/"
<IfFile /var/www/html/_control/debug>
php_value display_startup_errors on
php_value display_errors stderr
</IfFile>
# We turn off automatic addition of slashes for directories because it
# interferes with the file extension removal for .php files. At the bottom of
# this file, we have a redirect rule to mimic the same behaviour, _after_ the
# relevant rewrite rules have been applied
DirectorySlash off
RewriteEngine on
RewriteBase /
# Add mime type for apple-app-site-association
AddType application/json apple-app-site-association
# Custom error messages
# ErrorDocument 404 /_includes/errors/404.php
# apple-app-site-association
RewriteRule "^.well-known/apple-app-site-association$" "/.well-known/apple-app-site-association.json" [L]
# macosx and macos to mac (ignore case)
RewriteRule "^(macosx|macos)\b(.*)$" "/mac$2" [NC,R=301,END,QSA]
# Redirect deprecated Google Plus link
RewriteRule "^plus.*" "/" [NC,R=301,END,QSA]
# /donate -> donate.keyman.com
RedirectMatch 301 "^(?i)/donate(\/.*)?" "https://donate.keyman.com"
# /privacy -> SIL Privacy policy
RedirectMatch 301 "^(?i)/privacy(\/.*)?" "https://software.sil.org/language-software-privacy-policy/"
# desktop to windows
RewriteRule "^desktop(/.*)?" "/windows$1" [NC,R=301,END,QSA]
# releases-tier/download
# note: the tier is currently ignored
RewriteRule "^downloads/releases/(alpha|beta|stable)/(.+)$" "/downloads/releases/_version_downloads.php?tier=$1&version=$2" [END]
# releases-download
RewriteRule "^downloads/releases/(.+)$" "/downloads/releases/_version_downloads.php?version=$1" [END]
# index
RewriteRule "^downloads/releases(\/)?$" "/downloads" [R,END]
# CLDR -> LDML
RewriteRule "^cldr(\/)?$" "/ldml" [R=301,END]
#
# Keyboard landing pages (TODO)
#
# Cleanup various URLS with permanent redirects
# /keyboards/{install|download|share}/{id}/ to /keyboards/x/id
# Remove final /
RewriteRule "^keyboards/(install|download|share)/([^/]+)/$" "/keyboards/$1/$2" [R=301,END,QSA]
# /keyboards/{id}/ to /keyboards/id
# Remove final /
RewriteRule "^keyboards/([^/]+)/$" "/keyboards/$1" [R=301,END,QSA]
# /keyboards/ to /keyboards (Handled by other redirect)
# Remove final /
# Old share url /keyboards/{id}/share[/] to /keyboards/share/id
RewriteRule "^keyboards/(.*)/share(/?)$" "/keyboards/share/$1" [R=301]
# /keyboard/{content} to /keyboards/...
RewriteRule "^keyboard(/.*)$" "/keyboards$1" [R,END]
#
# Install | Download | Share | bare | .json -->
#
# /keyboards/install/[id] to /keyboards/install.php
RewriteRule "^keyboards/install/([^/]+)$" "/keyboards/install.php?id=$1" [END,QSA]
# /keyboards/download/[id] to /keyboards/keyboard.php
# This formerly redirected to a download, but we no longer need it; keep it for
# legacy links
RewriteRule "^keyboards/download/([^/]+)$" "/keyboards/keyboard.php?id=$1" [END,QSA]
# /keyboards/share/[id] to /keyboards/share.php
# if the keyboard exists in the repo, then share.php will redirect to /keyboards/<id>
RewriteRule "^keyboards/share/([^/]+)$" "/keyboards/share.php?id=$1" [END]
# /keyboards/{id}.json to /keyboards/keyboard.json.php
RewriteRule "^keyboards/(?!keyboard.json)(.*)\.json$" "/keyboards/keyboard.json.php?id=$1" [END]
# /keyboards/{id} to /keyboards/keyboard.php
RewriteRule "^keyboards/(?!index\.php|install|keyboard|session|share)([^/]+)$" "/keyboards/keyboard.php?id=$1" [END,QSA]
#
# Search
#
# /keyboards?q=... to /keyboards/index.php
# RewriteRule "^keyboards$" "/keyboards/index.php" [L]
# /keyboards/languages to /keyboards/index.php
RewriteRule "^keyboards/languages/(.*)" "/keyboards/index.php?q=l:id:$1" [END,QSA]
# /keyboards/download to /keyboards/download.php
RewriteRule "^keyboards/download(.php)?" "/keyboards/download.php" [END,QSA]
# /keyboards/legacy to /keyboards/keyboard.php
RewriteRule "^keyboards/legacy/(.*)" "/keyboards/keyboard.php?legacy=$1" [END]
# /keyboards/countries to /keyboards/index.php
RewriteRule "^keyboards/countries/(.*)" "/keyboards/index.php?q=c:id:$1" [END]
# Synonym paths
# 10.0 to 15.0
# /1X.0 to /1X landing page
RedirectMatch "^/1([0-5])(\.0)\/?" "/1$1/"
# ios
RedirectMatch "^/(?!iphone-and-ipad)(ios|iphone|ipad)(\/.*)?" "/iphone-and-ipad$2"
# Connect With Art landing page
RedirectMatch "/connectwithart(\/|$)" "https://sites.google.com/sil.org/connectwithart/home"
RedirectMatch "^/lt4all(/?)$" "/ldml/lt4all"
# per-language landing pages
RedirectMatch "^/albanian(/?)$" "/keyboards/basic_kbdal"
RedirectMatch "^/ancient-egyptian(/?)$" "/keyboards/hieroglyphic"
RedirectMatch "^/ancient-hebrew(/?)$" "/keyboards/galaxie_greek_hebrew_mnemonic"
RedirectMatch "^/arabic(/?)$" "/keyboards/basic_kbda1"
RedirectMatch "^/assamese(/?)$" "/keyboards/isis_bangla"
RedirectMatch "^/basic_kbdsn1(/?)$" "/keyboards/basic_kbdsn1"
RedirectMatch "^/bengali(/?)$" "/keyboards/basic_kbdinbe2"
RedirectMatch "^/cherokee(/?)$" "/keyboards/cherokee6"
RedirectMatch "^/cheyenne(/?)$" "/keyboards/sil_cheyenne"
RedirectMatch "^/dinka(/?)$" "/keyboards/el_dinka"
RedirectMatch "^/dutch(/?)$" "/keyboards/basic_kbdne"
RedirectMatch "^/farsi(/?)$" "/keyboards/farsi_unicode"
RedirectMatch "^/hebrew(/?)$" "/keyboards/basic_kbdheb"
RedirectMatch "^/hindi(/?)$" "/keyboards/basic_kbdindev"
RedirectMatch "^/igbo(/?)$" "/keyboards/sil_nigeria_dot"
RedirectMatch "^/khmer(/?)$" "/keyboards/khmer_angkor"
RedirectMatch "^/lao(/?)$" "/keyboards/basic_kbdlao"
RedirectMatch "^/malayalam(/?)$" "/keyboards/basic_kbdinmal"
RedirectMatch "^/maltese(/?)$" "/keyboards/maltese"
RedirectMatch "^/marathi(/?)$" "/keyboards/basic_kbdinmar"
RedirectMatch "^/mongolian(/?)$" "/keyboards/basic_kbdmon"
RedirectMatch "^/nepali(/?)$" "/keyboards/basic_kbdnepr"
RedirectMatch "^/oriya(/?)$" "/keyboards/basic_kbdinori"
RedirectMatch "^/rawang(/?)$" "/keyboards/rawang"
RedirectMatch "^/russian(/?)$" "/keyboards/basic_kbdru"
RedirectMatch "^/serbian(/?)$" "/keyboards/basic_kbdycc"
RedirectMatch "^/sindhi(/?)$" "/keyboards/mbsindhi"
RedirectMatch "^/thai(/?)$" "/keyboards/thai-uni"
RedirectMatch "^/yiddish(/?)$" "/keyboards/yiddish_pasekh"
RedirectMatch "^/yoruba(/?)$" "/keyboards/sil_yoruba8"
RedirectMatch "^/ancient-greek(/?)$" "/keyboards/h/greek"
RedirectMatch "^/(french|german|italian|spanish|swedish)(/?)$" "/keyboards/h/eurolatin"
# dedicated-keyboard-landing pages
RedirectMatch 301 "^/(amharic|burmese|cameroon|ethiopic|eurolatin|greek|ipa|sinhala|tamil|tibetan|tigrigna|urdu)(/.*)?$" "/keyboards/h/$1$2"
#
# PHP and Markdown rewriting
#
# Remove index or index.php and redirect (and stop processing)
RewriteCond "$1" -d
RewriteRule "^((.+)/)?index(\.php)?$" "$1" [R,L]
# Remove .php extension and redirect
RewriteCond "$1.php" -f
RewriteCond "$1" !-d
RewriteRule "^(.+)\.php$" "$1" [R,L]
# Redirect folder without / to include /
RewriteCond "{DOCUMENT_ROOT}/$1" -d
RewriteCond "{DOCUMENT_ROOT}/$1.php" !-f
RewriteCond "{DOCUMENT_ROOT}/$1.md" !-f
RewriteRule "^(.+[^/])$" "$1/" [R,END]
#
# PHP rewriting
#
# TODO: mdhost currently in a different path than help.keyman
# Rewrite file to file.md
RewriteCond "%{DOCUMENT_ROOT}/$1.md" -f
RewriteRule "^(.+)$" "/_includes/includes/md/mdhost.php?file=$1.md" [END]
# Rewrite file to file.php
RewriteCond "%{DOCUMENT_ROOT}/$1.php" -f
RewriteCond "%{DOCUMENT_ROOT}/$1.md" !-f
RewriteRule "^(.+)$" "$1.php" [END]
# Rewrite folder/ to folder/index.md
RewriteCond "%{DOCUMENT_ROOT}/$1/index.md" -f
RewriteRule "^(.+)/$" "/_includes/includes/md/mdhost.php?file=$1/index.md" [END]
# Rewrite folder/ to folder/index.php
RewriteCond "%{DOCUMENT_ROOT}/$1/index.php" -f
RewriteCond "%{DOCUMENT_ROOT}/$1/index.md" !-f
RewriteRule "^(.+)/$" "$1/index.php" [END]
# Finally, append the terminating slash for folders, given it is no longer
# done automatically because we put DirectorySlash off
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule "^(.*)([^/])$" "$1$2/" [R]