@@ -28,6 +28,85 @@ ErrorDocument 404 /_includes/errors/404.php
2828
2929RewriteRule "^_includes/errors/404(.php)?$" "/_includes/errors/404.php" [END]
3030
31+ # ##############################################################################
32+ #
33+ # Keyman 14.0 - 18.0 have a dependency on /keyboards which means that we cannot
34+ # rewrite URLs there when we are in 'embed' mode for those apps. The apps check
35+ # if the URL starts with /keyboards, and handle those paths internally, while
36+ # opening other URLs in an external browser.
37+ #
38+ # See https://github.com/keymanapp/keyman/issues/15948 for platform-specific
39+ # dependencies on this behaviour and for v19.0 planned mitigations.
40+ #
41+ # These rules are duplicated for the locale-aware versions for web browser
42+ # visitors later in this file.
43+ #
44+ # ##############################################################################
45+
46+ #
47+ # keyboards Install | Download | Share | bare | .json -->
48+ #
49+
50+ # /keyboards/install/[id] to /keyboards/install.php
51+ RewriteCond "%{HTTP_COOKIE}" embed_keyboards_no_locale_redirect [OR]
52+ RewriteCond "%{QUERY_STRING}" embed
53+ RewriteRule "^keyboards/install/([^/]+)$" "/_content/keyboards/install.php?id=$1" [END,QSA]
54+
55+ # /keyboards/download/[id] to /keyboards/keyboard.php
56+ # This formerly redirected to a download, but we no longer need it; keep it for
57+ # legacy links
58+ RewriteCond "%{HTTP_COOKIE}" embed_keyboards_no_locale_redirect [OR]
59+ RewriteCond "%{QUERY_STRING}" embed
60+ RewriteRule "^keyboards/download/([^/]+)$" "/_content/keyboards/keyboard.php?id=$1" [END,QSA]
61+
62+ # /keyboards/share/[id] to /keyboards/share.php
63+ # if the keyboard exists in the repo, then share.php will redirect to /keyboards/<id>
64+ RewriteCond "%{HTTP_COOKIE}" embed_keyboards_no_locale_redirect [OR]
65+ RewriteCond "%{QUERY_STRING}" embed
66+ RewriteRule "^keyboards/share/([^/]+)$" "/_content/keyboards/share.php?id=$1" [END,QSA]
67+
68+ # /keyboards/{id}.json to /keyboards/keyboard.json.php
69+ RewriteCond "%{HTTP_COOKIE}" embed_keyboards_no_locale_redirect [OR]
70+ RewriteCond "%{QUERY_STRING}" embed
71+ RewriteRule "^keyboards/(?!keyboard.json)(.*)\.json$" "/_content/keyboards/keyboard.json.php?id=$1" [END]
72+
73+ # /keyboards/{id} to /keyboards/keyboard.php
74+ RewriteCond "%{HTTP_COOKIE}" embed_keyboards_no_locale_redirect [OR]
75+ RewriteCond "%{QUERY_STRING}" embed
76+ RewriteRule "^keyboards/(?!index\.php|install|keyboard|session|share)([^/]+)$" "/_content/keyboards/keyboard.php?id=$1" [END,QSA]
77+
78+ #
79+ # keyboards search
80+ #
81+
82+ # /keyboards/languages to /keyboards/index.php
83+ RewriteCond "%{HTTP_COOKIE}" embed_keyboards_no_locale_redirect [OR]
84+ RewriteCond "%{QUERY_STRING}" embed
85+ RewriteRule "^keyboards/languages/(.*)" "/_content/keyboards/index.php?q=l:id:$1" [END,QSA]
86+
87+ # /keyboards/download to /keyboards/download.php
88+ RewriteCond "%{HTTP_COOKIE}" embed_keyboards_no_locale_redirect [OR]
89+ RewriteCond "%{QUERY_STRING}" embed
90+ RewriteRule "^keyboards/download(.php)?" "/_content/keyboards/download.php" [END,QSA]
91+
92+ # /keyboards/legacy to /keyboards/keyboard.php
93+ RewriteCond "%{HTTP_COOKIE}" embed_keyboards_no_locale_redirect [OR]
94+ RewriteCond "%{QUERY_STRING}" embed
95+ RewriteRule "^keyboards/legacy/(.*)" "/_content/keyboards/keyboard.php?legacy=$1" [END]
96+
97+ # /keyboards/countries to /keyboards/index.php
98+ RewriteCond "%{HTTP_COOKIE}" embed_keyboards_no_locale_redirect [OR]
99+ RewriteCond "%{QUERY_STRING}" embed
100+ RewriteRule "^keyboards/countries/(.*)" "/_content/keyboards/index.php?q=c:id:$1" [END]
101+
102+ # Root keyboard search to pass embed query?
103+ RewriteCond "%{HTTP_COOKIE}" embed_keyboards_no_locale_redirect [OR]
104+ RewriteCond "%{QUERY_STRING}" embed
105+ RewriteRule "^keyboards(/)?$" "/_content/keyboards/index.php" [END,QSA]
106+
107+
108+
109+
31110# ##################################################################
32111# Reject special and legacy top-level files without i18n
33112# ##################################################################
@@ -64,14 +143,6 @@ RewriteRule "^(_common/assets)/(.+)$" - [END]
64143RewriteRule "^(_common|_content|_includes|_scripts|.github|resources|tests)(/.*|$)" - [F,END]
65144RewriteRule "^(.editorconfig|.gitattributes|.gitignore|build.sh|composer.json|composer.lock|crowdin.yml|Dockerfile|package-lock.json|package.json|phpunit.xml|README.md|TODO.md)$" - [F,END]
66145
67- #
68- # The following paths are accessible but controlled by sub-folder .htaccess:
69- # _legacy/
70- # Thus this rule currently has no effect but will come into play if the
71- # _legacy/.htaccess file is removed.
72- #
73- RewriteRule "^(_legacy)(/.*|$)" - [F,END]
74-
75146# ##################################################################
76147# Handle special and legacy top-level files without i18n
77148# ##################################################################
@@ -81,7 +152,6 @@ RewriteRule "^(_legacy)(/.*|$)" - [F,END]
81152# but have .php and .md rewrites. They do not have sub-folders.
82153# _common/assets/ (handled above because _common/ itself is excluded)
83154# _control/
84- # _ie_thunk/
85155# _test/
86156#
87157# The following top-level files and folders do not have .php or .md rewrites
@@ -96,26 +166,26 @@ RewriteRule "^(_legacy)(/.*|$)" - [F,END]
96166RewriteRule "^.well-known/apple-app-site-association$" "/.well-known/apple-app-site-association.json" [L]
97167
98168# Add terminating slash on top-level folders by redirecting
99- RewriteCond "$1" ^(_control|_ie_thunk| _test|.well-known|go|cdn)$
169+ RewriteCond "$1" ^(_control|_test|.well-known|go|cdn)$
100170RewriteRule "^([^/]+)$" "$1/" [R,L]
101171
102172# .php rewrite
103- RewriteCond "$1" ^(_control|_ie_thunk| _test)$
173+ RewriteCond "$1" ^(_control|_test)$
104174RewriteCond "%{DOCUMENT_ROOT}/$1/$2.php" -f
105175RewriteRule "^([^/]+)/(.+)$" "/$1/$2.php" [END]
106176
107177# .md rewrite
108- RewriteCond "$1" ^(_control|_ie_thunk| _test)$
178+ RewriteCond "$1" ^(_control|_test)$
109179RewriteCond "%{DOCUMENT_ROOT}/$1/$2.md" -f
110180RewriteRule "^([^/]+)/(.+)$" "/_includes/includes/md/mdhost.php?file=$1/$2.md" [END]
111181
112182# .md rewrite for folder; no .php rewrite for folder
113- RewriteCond "$1" ^(_control|_ie_thunk| _test)$
183+ RewriteCond "$1" ^(_control|_test)$
114184RewriteCond "%{DOCUMENT_ROOT}/$1/index.md" -f
115185RewriteRule "^([^/]+)/$" "/_includes/includes/md/mdhost.php?file=$1/index.md" [END]
116186
117187# Any existing file in any of those folders or sub folders
118- RewriteCond "$1" ^(_control|_ie_thunk| _test|.well-known|go|cdn)$
188+ RewriteCond "$1" ^(_control|_test|.well-known|go|cdn)$
119189RewriteCond "%{DOCUMENT_ROOT}/$1/$2" -f
120190RewriteRule "^([^/]+)/(.+)$" - [END]
121191
0 commit comments