Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,64 @@ RewriteRule "^((.+)/)?index(\.md|\.php)?$" "$1" [R,L]
RewriteRule "^(.+)\.php$" "$1" [R,L]
RewriteRule "^(.+)\.md$" "$1" [R,L]

# Redirect folder without / to include /
# ------------------------------------------------------------------
# Add and remove `/` for folders and files for consistency
# ------------------------------------------------------------------

#
# Note: we don't test the content of the lang path parameter (?:[^/]+)/
# here; that is managed exclusively in the i18n section later.
#

# Redirect folder to folder/ for .php
RewriteCond "%{DOCUMENT_ROOT}/_content/$2" -d
RewriteCond "%{DOCUMENT_ROOT}/_content/$2/index.php" -f
RewriteRule "^([^/]+)/(.+[^/])$" "$1/$2/" [R,L]

# Redirect folder to folder/ for .md
RewriteCond "%{DOCUMENT_ROOT}/_content/$2" -d
RewriteCond "%{DOCUMENT_ROOT}/_content/$2/index.md" -f
RewriteRule "^([^/]+)/(.+[^/])$" "$1/$2/" [R,L]

# Redirect file/ to file (.md)
RewriteCond "%{DOCUMENT_ROOT}/_content/$2" !-d
RewriteCond "%{DOCUMENT_ROOT}/_content/$2.md" -f
RewriteRule "^([^/]+)/(.+)/$" "$1/$2" [R,L]

# Redirect file/ to file (.php)
RewriteCond "%{DOCUMENT_ROOT}/_content/$2" !-d
RewriteCond "%{DOCUMENT_ROOT}/_content/$2.php" -f
RewriteRule "^([^/]+)/(.+)/$" "$1/$2" [R,L]

#
# top-level folders and files
#

# Redirect folder to folder/ for .php
RewriteCond "%{DOCUMENT_ROOT}/$1" -d
RewriteCond "%{DOCUMENT_ROOT}/$1.php" !-f
RewriteCond "%{DOCUMENT_ROOT}/$1.md" !-f
RewriteRule "^(.+[^/])$" "$1/" [R,END]
RewriteCond "%{DOCUMENT_ROOT}/$1/index.php" -f
RewriteRule "^(.+[^/])$" "$1/" [R,L]

# Redirect folder to folder/ for .md
RewriteCond "%{DOCUMENT_ROOT}/$1" -d
RewriteCond "%{DOCUMENT_ROOT}/$1/index.md" -f
RewriteRule "^(.+[^/])$" "$1/" [R,L]

# Redirect file/ to file (.md)
RewriteCond "%{DOCUMENT_ROOT}/$1" !-d
RewriteCond "%{DOCUMENT_ROOT}/$1.md" -f
RewriteRule "^(.+)/$" "$1" [R,L]

# Redirect file/ to file (.php)
RewriteCond "%{DOCUMENT_ROOT}/$1" !-d
RewriteCond "%{DOCUMENT_ROOT}/$1.php" -f
RewriteRule "^(.+)/$" "$1" [R,L]

# ------------------------------------------------------------------
# Known path redirections
# ------------------------------------------------------------------

# Redirect /archive/downloads.php"
# Redirect /archive/downloads.php
RewriteRule "^archive/downloads(.php)?$" "/downloads/archive/" [NC,R=301,END,QSA]

# ios and iphone and ipad to iphone-and-ipad
Expand Down Expand Up @@ -315,6 +362,6 @@ RewriteRule "^(([a-z]{2,3})(-([A-Za-z]{4}))?(-([a-z]{2}|[0-9]{3}))?)/(.+)/$" "/_
RewriteRule "^(([a-z]{2,3})(-([A-Za-z]{4}))?(-([a-z]{2}|[0-9]{3}))?)/$" "/_content/index.php?lang=$1" [NC,END]

# Finally, append the terminating slash for folders, given it is no longer
# done automatically because we put DirectorySlash off
# done automatically because we put DirectorySlash off, for the top-level paths only
RewriteCond "%{DOCUMENT_ROOT}/_content/$7$8" -d
RewriteRule "^(([a-z]{2,3})(-([A-Za-z]{4}))?(-([a-z]{2}|[0-9]{3}))?)(.*)([^/])?$" "$1$7$8/" [NC,R,QSA]
8 changes: 5 additions & 3 deletions _content/keyboards/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function _m($id, ...$args) { return Locale::m(LOCALE_KEYBOARDS, $id, ...$args
if($embed == 'none')
Menu::render([]); // we'll be doing client-side os detection now
Body::render();

$keyboardsPage = '/' . $head_options['language'] . '/keyboards';
?>

<script>
Expand All @@ -59,14 +61,14 @@ function _m($id, ...$args) { return Locale::m(LOCALE_KEYBOARDS, $id, ...$args

<div class='<?= $embed == 'none' ? '' : 'embed embed-'.$embed ?>'>

<h2 class="red underline"><a href='/<?= $head_options['language']?>/keyboards'><?= _m('page_title') ?></a></h2>
<h2 class="red underline"><a href='<?=$keyboardsPage?>'><?= _m('page_title') ?></a></h2>

<div id='search-box'>
<form method='get' action='/<?= $head_options['language']?>/keyboards' name='f'>
<form method='get' action='<?=$keyboardsPage?>' name='f'>
<label for="search-q"><?= _m('keyboard_search') ?></label><input id="search-q" type="text" placeholder="<?= _m('enter_language') ?>" name="q"
<?php if($embed == 'none') echo 'autofocus'; ?>>
<input id="search-f" type="button" value="<?= _m('search') ?>">
<label id="search-new"><a href='/<?= $head_options['language']?>/keyboards<?=$session_query_q?>'><?= _m('new_search')?></a></label>
<label id="search-new"><a href='<?= $keyboardsPage . $session_query_q?>'><?= _m('new_search')?></a></label>
<input id="search-obsolete" type="hidden" name="obsolete" value="0">
<input id="search-page" type="hidden" name="page" value="1">
</form>
Expand Down
6 changes: 3 additions & 3 deletions cdn/dev/keyboard-search/search.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var embed_query_q = embed_query == '' ? '' : '?'+embed_query;
var embed_query_x = embed_query == '' ? '' : '&'+embed_query;

// TODO: Validate BCP-47 triplet?
var langMatch = location.pathname.match(/(\/(.+))?\/keyboards(.*)$/);
var langMatch = location.pathname.match(/(\/(.+))?\/keyboards\/(.*)$/);
var embed_lang = (langMatch) ? langMatch[2] : 'en';

var dynamic_search_timeout = 0;
Expand All @@ -49,9 +49,9 @@ function getCurrentPath(q, page, obsolete) {
} else if(r && r[1].charAt(0) == 'l') {
path = '/' + embed_lang + '/keyboards/languages/'+r[3];
} else if(q == '') {
path = '/' + embed_lang + '/keyboards'
path = '/' + embed_lang + '/keyboards/'
} else {
path = '/' + embed_lang + '/keyboards?q='+encodeURIComponent(q);
path = '/' + embed_lang + '/keyboards/?q='+encodeURIComponent(q);
}

if(page + obsolete == '') {
Expand Down
7 changes: 6 additions & 1 deletion resources/keyman-site.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

DirectoryIndex index.md index.php index.html

<Directory /var/www/html>
<Directory /var/www/html>
Options +Includes +FollowSymLinks -MultiViews
AllowOverride All

## enable the LogLevel line below to trace mod_rewrite in the Docker logs.
## Note: traceX where X can be anything from 1-8
# LogLevel alert rewrite:trace3

</Directory>

php_value include_path "/var/www/html/_includes:."
Expand Down
Loading