forked from keymanapp/help.keyman.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.htaccess
245 lines (184 loc) · 9.16 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# 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 /
# Custom error messages (need to pass the original request)
ErrorDocument 404 /_includes/errors/404
# Handle IIS bug which created links to /DEVELOPER instead of /developer
RedirectMatch "/DEVELOPER(.*)" "/developer$1"
#
# Keyboard redirects -- must go before current-version
#
# Redirect broken legacy keyboard links
RewriteRule "^keyboard/gff_(mdx|muz|suq)_7(/.*)?" "keyboard/gff_mym_7$2" [R,L]
RewriteRule "^keyboard/redir.php(.*)$" - [END]
# Rewrite /keyboard/[name][/] to /keyboard/redir.php?q=[name]
# only if index.php does not exist in the folder
RewriteCond "%{DOCUMENT_ROOT}/keyboard/$1/index.php" !-f
RewriteRule "^keyboard/(?!redir.php)([^/?]+)(/)?$" "keyboard/redir.php?q=$1" [END]
# Rewrite /keyboard/name/current-version[/] to /keyboard/redir.php?q=[name]
RewriteRule "^keyboard/(?!redir.php)([^/?]+)/current-version(/)?$" "keyboard/redir.php?q=$1" [END]
# Rewrite /keyboard/[name]/[version][/] to /keyboard/redir.php?q=[name]&v=[version]
# only if index.php does not exist in the folder
RewriteCond "%{DOCUMENT_ROOT}/keyboard/$1/$2/index.php" !-f
RewriteRule "^keyboard/(?!redir.php)([^/?]+)/([^/?]+)(/)?$" "keyboard/redir.php?q=$1&v=$2" [END]
# versioning: these rules automatically redirect /foo/current-version to the
# newest version of the documentation under /foo, e.g. 13.0, /foo/13.0, and fall
# back to previous versions if no newer version is available. When we release a
# new version, we need to add in the rule for that version. 10.0 is the oldest
# version which falls under this pattern.
#
# The current-version:\d+.\d+ tag is used by the versioning script to get the
# current version (we can't simply use the newest because there may be alpha
# content on the site).
#
# When we add in the new version rule, remove the current- prefix from the
# older version. There are 3 places to insert the version number into the rule.
# # current-version:XX.0
# RewriteCond "%{DOCUMENT_ROOT}/$1/XX.0" -d
# RewriteRule "^(.+)/current-version(/.*)?$" "$1/XX.0$2"
# Redirect unversioned paths to current-version/ path
# /products first
RedirectMatch "/products/(android|iphone-and-ipad|linux|mac|web|windows)/(?!latest-version|current-version|version-history|\d+\.\d+)(.*)" "/products/$1/current-version/$2"
# /developer/engine/ for Android and iOS
RedirectMatch "/developer/engine/(android|iphone-and-ipad)/(?!latest-version|current-version|\d+\.\d+)(.*)" "/developer/engine/$1/current-version/$2"
# /developer/engine/web
RedirectMatch "/developer/engine/web/(?!latest-version|faq|history|current-version|\d+\.\d+)(.*)" "/developer/engine/web/current-version/$1"
# latest-version:18.0
# alpha or beta version reference
RewriteCond "%{DOCUMENT_ROOT}/$1/18.0" -d
RewriteRule "^(.+)/latest-version(/.*)?$" "$1/18.0$2" [DPI]
# current-version:17.0
RewriteCond "%{DOCUMENT_ROOT}/$1/17.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/17.0$2" [DPI]
# version:16.0
RewriteCond "%{DOCUMENT_ROOT}/$1/16.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/16.0$2" [DPI]
# version:15.0
RewriteCond "%{DOCUMENT_ROOT}/$1/15.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/15.0$2" [DPI]
# version:14.0
RewriteCond "%{DOCUMENT_ROOT}/$1/14.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/14.0$2" [DPI]
# version:13.0
RewriteCond "%{DOCUMENT_ROOT}/$1/13.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/13.0$2" [DPI]
# version:12.0
RewriteCond "%{DOCUMENT_ROOT}/$1/12.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/12.0$2" [DPI]
# version:11.0
RewriteCond "%{DOCUMENT_ROOT}/$1/11.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/11.0$2" [DPI]
# version:10.0
RewriteCond "%{DOCUMENT_ROOT}/$1/10.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/10.0$2" [DPI]
# the following version fallbacks are for APIs such as /developer/cloud versions
# version:9.0
RewriteCond "%{DOCUMENT_ROOT}/$1/9.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/9.0$2" [DPI]
# version:8.0
RewriteCond "%{DOCUMENT_ROOT}/$1/8.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/8.0$2" [DPI]
# version:7.0
RewriteCond "%{DOCUMENT_ROOT}/$1/7.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/7.0$2" [DPI]
# version:6.0
RewriteCond "%{DOCUMENT_ROOT}/$1/6.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/6.0$2" [DPI]
# version:5.0
RewriteCond "%{DOCUMENT_ROOT}/$1/5.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/5.0$2" [DPI]
# version:4.0
RewriteCond "%{DOCUMENT_ROOT}/$1/4.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/4.0$2" [DPI]
# version:3.0
RewriteCond "%{DOCUMENT_ROOT}/$1/3.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/3.0$2" [DPI]
# version:2.0
RewriteCond "%{DOCUMENT_ROOT}/$1/2.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/2.0$2" [DPI]
# version:1.0
RewriteCond "%{DOCUMENT_ROOT}/$1/1.0" -d
RewriteRule "^(.+)/(?:current|latest)-version(/.*)?$" "$1/1.0$2" [DPI]
# Static redirection
Redirect "/desktop" "/products/windows"
Redirect "/windows" "/products/windows"
Redirect "/android" "/products/android"
Redirect "/ipad" "/products/iphone-and-ipad"
Redirect "/iphone" "/products/iphone-and-ipad"
Redirect "/iphone-and-ipad" "/products/iphone-and-ipad"
Redirect "/ios" "/products/iphone-and-ipad"
Redirect "/products/ipad" "/products/iphone-and-ipad"
Redirect "/products/iphone" "/products/iphone-and-ipad"
Redirect "/products/ios" "/products/iphone-and-ipad"
Redirect "/linux" "/products/linux"
Redirect "/debian" "/products/linux"
Redirect "/ubuntu" "/products/linux"
Redirect "/mac" "/products/mac"
Redirect "/macos" "/products/mac"
Redirect "/macosx" "/products/mac"
Redirect "/products/macos" "/products/mac"
Redirect "/products/macosx" "/products/mac"
Redirect "/web" "/products/web"
Redirect "/keymanweb" "/products/web"
Redirect "/products/keymanweb" "/products/web"
Redirect "/bookmarklet" "/products/bookmarklet"
Redirect "/kb" "/knowledge-base"
# Redirect to kb handler
RewriteRule "^knowledge-base/(\d+)$" "/knowledge-base/index.php?id=$1" [L]
# Redirect error code shortlinks
# We could choose to enable this in the future, but for now we use the kmn.sh
# redirects instead.
# RedirectMatch "/go/(km\d+)$" "/developer/latest-version/reference/errors/$1"
#
# PHP and Markdown rewriting
#
# special case because of specific filenames : these don't redirect properly otherwise
# Rewrite nul -> _nul, index -> _index
RewriteRule "^developer/language/reference/(nul|index)(\.php|\.md)?$" "developer/language/reference/_$1$2"
# no pages currently reference this but will allow for future automatic re-versioning links in docs (13.0 onward?)
# Redirect creating-a-touch-keyboard-layout-for-amharic-with-keyman-developer-10
RewriteRule "^developer/(1[3-9].0)/guides/develop/creating-a-touch-keyboard-layout-for-amharic-with-keyman-developer-10(.*)?$" "developer/$1/guides/develop/creating-a-touch-keyboard-layout-for-amharic"
# Redirect how-to-test-your-keyboard-layout-with-keyman-developer-10-touch-and-desktop
RewriteRule "^developer/(1[3-9].0)/guides/test/how-to-test-your-keyboard-layout-with-keyman-developer-10-touch-and-desktop(.*)?$" "developer/$1/guides/test/keyboard-touch-and-desktop"
# Redirect how-to-test-your-touch-layout-in-the-google-chrome-mobile-emulator (removed in 16.0)
RewriteRule "^developer/(1[3-9].0)/guides/test/how-to-test-your-touch-layout-in-the-google-chrome-mobile-emulator(.*)?$" "developer/$1/guides/test/keyboard-touch-mobile-emulator"
# 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]
# Remove .php extension and redirect - but only for Keyman Developer API docs for now
RewriteCond "$1.md" -f
RewriteRule "^(developer/(current-version|\d+\.\d+)/reference/api/.+)\.md$" "$1" [R,END]
# 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
#
# Rewrite file to file.md
RewriteCond "%{DOCUMENT_ROOT}/$1.md" -f
RewriteRule "^(.+)$" "/_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/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]