File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,10 +17,20 @@ const SUBPROJECTS = {
1717 "/projects/owid-grapher-py/" : "https://owid-grapher-py-docs.pages.dev" ,
1818} ;
1919
20+ // Legacy ReadTheDocs URLs include an /en/latest segment (e.g.
21+ // /projects/etl/en/latest/, /en/latest/). 301 to the canonical form so
22+ // existing inbound links from blog posts / Slack / bookmarks keep working.
23+ const RTD_LEGACY = / \/ e n \/ l a t e s t ( \/ | $ ) / ;
24+
2025export default {
2126 async fetch ( request , env ) {
2227 const url = new URL ( request . url ) ;
2328
29+ if ( RTD_LEGACY . test ( url . pathname ) ) {
30+ url . pathname = url . pathname . replace ( RTD_LEGACY , "$1" ) || "/" ;
31+ return Response . redirect ( url . toString ( ) , 301 ) ;
32+ }
33+
2434 for ( const [ prefix , origin ] of Object . entries ( SUBPROJECTS ) ) {
2535 if ( url . pathname . startsWith ( prefix ) ) {
2636 const target = `${ origin } ${ url . pathname } ${ url . search } ` ;
You can’t perform that action at this time.
0 commit comments