From 7b8f74a55f2ab0c7f5d8a159128e2327936157f8 Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Thu, 6 Nov 2025 23:12:58 +0100 Subject: [PATCH 1/2] Fetch redirects based on the current URL. --- 404.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/404.rst b/404.rst index 0cf80c065a4..0f2100e6ba7 100644 --- a/404.rst +++ b/404.rst @@ -35,8 +35,12 @@ Page not found // Check for redirects if on a currently invalid page. // This is done in JavaScript, as we exceed Read the Docs' limit for the amount of redirects configurable. - // When testing this feature on a local web server, replace the URL below with just `/_static/redirects.csv`. - fetch("/en/latest/_static/redirects.csv") + + const currentPathSegments = window.location.pathname.split('/').filter(segment => segment !== ''); + // Use the base path (e.g. "/en/latest") when available + const currentBasePath = (currentPathSegments.length >= 2) ? ("/" + currentPathSegments.slice(0, 2).join("/")) : "/"; + + fetch(currentBasePath + "/_static/redirects.csv") .then(response => response.text()) .then(csvText => { const lines = csvText.trim().split('\n'); From b956e79a3c6ee79058644c57ae61bead6882b55f Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 12 Nov 2025 22:08:17 +0100 Subject: [PATCH 2/2] Apply suggestions from code review --- 404.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/404.rst b/404.rst index 0f2100e6ba7..1c6e22b4b35 100644 --- a/404.rst +++ b/404.rst @@ -37,7 +37,7 @@ Page not found // This is done in JavaScript, as we exceed Read the Docs' limit for the amount of redirects configurable. const currentPathSegments = window.location.pathname.split('/').filter(segment => segment !== ''); - // Use the base path (e.g. "/en/latest") when available + // Use the base path (e.g. "/en/latest") when available. const currentBasePath = (currentPathSegments.length >= 2) ? ("/" + currentPathSegments.slice(0, 2).join("/")) : "/"; fetch(currentBasePath + "/_static/redirects.csv")