Skip to content
Merged
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
10 changes: 10 additions & 0 deletions _worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ const SUBPROJECTS = {
"/projects/owid-grapher-py/": "https://owid-grapher-py-docs.pages.dev",
};

// Legacy ReadTheDocs URLs include an /en/latest segment (e.g.
// /projects/etl/en/latest/, /en/latest/). 301 to the canonical form so
// existing inbound links from blog posts / Slack / bookmarks keep working.
const RTD_LEGACY = /\/en\/latest(\/|$)/;

export default {
async fetch(request, env) {
const url = new URL(request.url);

if (RTD_LEGACY.test(url.pathname)) {
url.pathname = url.pathname.replace(RTD_LEGACY, "$1") || "/";
return Response.redirect(url.toString(), 301);
}

for (const [prefix, origin] of Object.entries(SUBPROJECTS)) {
if (url.pathname.startsWith(prefix)) {
const target = `${origin}${url.pathname}${url.search}`;
Expand Down
Loading