fix: handle redirects for paths and files with terminating slashes 🌋#717
fix: handle redirects for paths and files with terminating slashes 🌋#717mcdurdin merged 1 commit intofix/search-jsonfrom
Conversation
User Test ResultsTest specification and instructions User tests are not required |
95b97ef to
3471e04
Compare
a60dbfd to
c265b3c
Compare
c265b3c to
6c2562b
Compare
|
|
||
| <div class="download-cta-small iPhone" id="cta-iPhone"> | ||
| <a href="../../../iphone/"> | ||
| <a href="../../../iphone-and-ipad/"> |
There was a problem hiding this comment.
We keep /ipad and /iphone as top-level redirects, but we don't need those for e.g. /en/ipad as the content is all at /_content/iphone-and-ipad. This eliminates a rule in the .htaccess
| <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> |
There was a problem hiding this comment.
This line was broken (nested <?=), when I fixed it I decided to simplify all references
| # ------------------------------------------------------------------ | ||
| # top-level content without i18n - _control/, go/, _test/, cdn | ||
| # ------------------------------------------------------------------ | ||
|
|
||
| # No i18n - won't go to _content | ||
|
|
||
| RewriteCond "%{DOCUMENT_ROOT}/$1/$2.php" -f | ||
| RewriteRule "^(_control|go|_test)/(.+)$" "/$1/$2.php" [END] | ||
|
|
||
| RewriteCond "%{DOCUMENT_ROOT}/$1/$2.md" -f | ||
| RewriteRule "^(_control|go|_test)/(.+)$" "/_includes/includes/md/mdhost.php?file=$1/$2.md" [END] | ||
|
|
||
| RewriteCond "%{DOCUMENT_ROOT}/$1/index.md" -f | ||
| RewriteRule "^(_control|go|_test)(/?)$" "/_includes/includes/md/mdhost.php?file=$1/index.md" [END] | ||
|
|
||
| RewriteCond "%{DOCUMENT_ROOT}/cdn/$1$2" -f | ||
| RewriteRule "^cdn/(.+\.)(gif|js|png|svg)$" "/cdn/$1$2" [END] |
There was a problem hiding this comment.
This section is now moved up
| RewriteRule "^(([a-z]{2,3})(-([A-Za-z]{4}))?(-([a-z]{2}|[0-9]{3}))?)/keyboards/install/([^/]+)$" "/_content/keyboards/install.php?id=$7&lang=$1" [NC,END,QSA] | ||
| RewriteCond "$1" ^([a-z]{2,3})(-([A-Za-z]{4}))?(-([a-z]{2}|[0-9]{3}))?$ [NC] # BCP 47 match | ||
| RewriteRule "^([^/]+)/keyboards/install/([^/]+)$" "/_content/keyboards/install.php?id=$2&lang=$1" [END,QSA] |
There was a problem hiding this comment.
Hmm, was going to put these into a separate PR ... but was working on them and pushed accidentally. Let's see how they go!
darcywong00
left a comment
There was a problem hiding this comment.
ahh, nice cleanup! thanks
| # TODO.md | ||
| # | ||
| RewriteRule "^(_common|_content|_includes|_scripts|.github|resources|tests)(/.*|$)" - [F,END] | ||
| RewriteRule "^(.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] |
There was a problem hiding this comment.
Does this need - [F,END] like in the other lines?
| RewriteCond "$1" ^(_control|_test|_ie_thunk|.well-known|go|cdn)$ | ||
| RewriteRule "^([^/]+)$" "$1/" [R,L] | ||
|
|
||
| # .php rewrite | ||
| RewriteCond "$1" ^(_control|_test|_ie_thunk)$ | ||
| RewriteCond "%{DOCUMENT_ROOT}/$1/$2.php" -f | ||
| RewriteRule "^([^/]+)/(.+)$" "/$1/$2.php" [END] | ||
|
|
||
| # .md rewrite | ||
| RewriteCond "$1" ^(_control|_test|_ie_thunk)$ | ||
| RewriteCond "%{DOCUMENT_ROOT}/$1/$2.md" -f | ||
| RewriteRule "^([^/]+)/(.+)$" "/_includes/includes/md/mdhost.php?file=$1/$2.md" [END] | ||
|
|
||
| # .md rewrite for folder; no .php rewrite for folder | ||
| RewriteCond "$1" ^(_control|_test|_ie_thunk)$ | ||
| RewriteCond "%{DOCUMENT_ROOT}/$1/index.md" -f | ||
| RewriteRule "^([^/]+)/$" "/_includes/includes/md/mdhost.php?file=$1/index.md" [END] | ||
|
|
||
| # Any existing file in any of those folders or sub folders | ||
| RewriteCond "$1" ^(_control|_ie_thunk|_test|.well-known|go|cdn)$ |
There was a problem hiding this comment.
To help me with future maintenance, can we have the RewriteConds in the same sort order as the commented folder listing (ll 80-88)?
e.g.
RewriteCond "$1" ^(_control|_ie_thunk|_test)$
and
RewriteCond "$1" ^(_control|_ie_thunk|_test|.well-known|cdn|go)$
There was a problem hiding this comment.
For sure, was aiming for alphabetical but moved some things around and missed those. Will cleanup
|
|
||
| # Redirect folder without / to include / | ||
| # ------------------------------------------------------------------ | ||
| # Add and remove `/` for folders and files for consistency |
There was a problem hiding this comment.
maybe wordsmithing something like
| # Add and remove `/` for folders and files for consistency | |
| # For trailing '/' consistency: Add '/' for folders and remove `/` for files |
| Menu::render([]); // we'll be doing client-side os detection now | ||
| Body::render(); | ||
|
|
||
| $keyboardsPage = '/' . $head_options['language'] . '/keyboards'; |
There was a problem hiding this comment.
Devin asks if $keyboardPage missing a trailing slash causes unnecessary 302 redirects.
New .htaccess rules at lines 62-64 redirect
/en/keyboards->/en/keyboards/because_content/keyboardsis a directory containing index.php
...
When a user presses Enter in the search box, this causes an unnecessary redirect from/en/keyboards?q=...to/en/keyboards/?q=...
Remove the `/` from a path if it refers to a file, and add a `/` if the path refers to a folder (implicit index.md/index.php). Clean up keyboard search which had some assumptions about not including the `/` but that doesn't make sense with this pattern. Test-bot: skip
6c2562b to
dea9d6b
Compare
Remove the
/from a path if it refers to a file, and add a/if the path refers to a folder (implicit index.md/index.php).Clean up keyboard search which had some assumptions about not including the
/but that doesn't make sense with this pattern.Test-bot: skip