Skip to content

Commit 4c63836

Browse files
committed
fix: redirect deep links to their Medium article instead of 404
The site only redirected the root. index.html was served for / and redirected to the publication home, but GitHub Pages returned its generic 404 for any other path, so links that worked while Medium hosted the blog.rook.io custom domain (e.g. blog.rook.io/rook-v1-20-storage-enhancements-5331368a5936) broke. index.html now builds the redirect target from the request path rather than hardcoding the publication home, and a new 404.html carries the same content. GitHub Pages serves 404.html for any path without a matching file, so every deep link redirects to the matching slug under medium.com/rook-io. The bare root still redirects to the publication home. Signed-off-by: Jared Watts <jbw976@gmail.com>
1 parent 0466306 commit 4c63836

3 files changed

Lines changed: 45 additions & 11 deletions

File tree

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ https://medium.com/rook-io/.
66
Medium removed their previous support for custom domains (see rook/rook#17938), so this static
77
Github Pages site is a simple alternative for it.
88

9-
This site simply performs a client side redirect to https://medium.com/rook-io/ in this priority
10-
order:
9+
GitHub Pages serves `index.html` for the root and `404.html` for every other path, which covers the
10+
old custom domain's deep links (e.g. `blog.rook.io/rook-v1-20-storage-enhancements-5331368a5936`).
11+
Both forward the request path unchanged to `https://medium.com/rook-io<path>`, so deep links should
12+
land on their exact article.
1113

12-
1. `location.replace()` in `<head>`
13-
1. `<meta http-equiv="refresh">` fallback for browsers without JavaScript
14-
1. a static link on the page if meta refresh is not supported
14+
The redirect is a client-side `location.replace()`, falling back to `<meta http-equiv="refresh">` and
15+
a static link for browsers without JavaScript. Only the JavaScript path preserves the request path;
16+
the fallbacks send the reader to the publication home.

public/404.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<title>Rook Blog</title>
7+
<script>
8+
// redirect to medium, but preserve any extra path information. pathname is "/" at the root
9+
// and "/<slug>" for a deep link, so this yields https://medium.com/rook-io/ or
10+
// https://medium.com/rook-io/<slug>. Keep any query string and fragment so anchored and
11+
// tracked links survive.
12+
var target =
13+
"https://medium.com/rook-io" +
14+
location.pathname +
15+
location.search +
16+
location.hash;
17+
location.replace(target);
18+
</script>
19+
<!-- Fallback for browsers with JavaScript disabled. -->
20+
<link rel="canonical" href="https://medium.com/rook-io/" />
21+
<meta http-equiv="refresh" content="0; url=https://medium.com/rook-io/" />
22+
</head>
23+
<body>
24+
<!-- Last resort if both scripting and meta refresh are unavailable. -->
25+
<noscript><a href="https://medium.com/rook-io/">Continue to the Rook blog on Medium</a></noscript>
26+
</body>
27+
</html>

public/index.html

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1" />
66
<title>Rook Blog</title>
7-
<!-- The Rook blog now lives on Medium; canonical points crawlers at its real home. -->
8-
<link rel="canonical" href="https://medium.com/rook-io/" />
9-
<!-- Runs while the <head> is still parsing, before the body paints, so the
10-
browser navigates without flashing an intermediate page. replace() leaves
11-
no history entry, so Back from Medium skips this page instead of looping. -->
127
<script>
13-
location.replace("https://medium.com/rook-io/");
8+
// redirect to medium, but preserve any extra path information. pathname is "/" at the root
9+
// and "/<slug>" for a deep link, so this yields https://medium.com/rook-io/ or
10+
// https://medium.com/rook-io/<slug>. Keep any query string and fragment so anchored and
11+
// tracked links survive.
12+
var target =
13+
"https://medium.com/rook-io" +
14+
location.pathname +
15+
location.search +
16+
location.hash;
17+
location.replace(target);
1418
</script>
1519
<!-- Fallback for browsers with JavaScript disabled. -->
20+
<link rel="canonical" href="https://medium.com/rook-io/" />
1621
<meta http-equiv="refresh" content="0; url=https://medium.com/rook-io/" />
1722
</head>
1823
<body>

0 commit comments

Comments
 (0)