diff --git a/public/404.html b/public/404.html index aadafb2..d0f0857 100644 --- a/public/404.html +++ b/public/404.html @@ -6,26 +6,32 @@ // Redirect to the correct URL var pathname = window.location.pathname; var search = window.location.search; - + // Remove leading slash from pathname if it exists if (pathname.startsWith('/')) { pathname = pathname.substring(1); } - - // Construct the new URL - let basePath = '/copilot-videos/#' + pathname.replace('copilot-videos', ''); - // If there are double slashes anywhere in the url, remove one + console.log(`pathname: ${basePath}`); + + // Construct the new URL (only needed for forks with a subfolder, should not be used on https://github-copilot.xebia.ms!) + let basePath = '/'; + if (!pathname.startsWith('https://github-copilot.xebia.ms')) { + // Redirect to the root of the fork + basePath = '/copilot-videos/#' + pathname.replace('copilot-videos', ''); + } + + // If there are double slashes anywhere in the url, remove them if (basePath.includes('//')) { basePath = basePath.replace('//', '/'); } // log the parts for debugging console.log(`search: ${search}`); - console.log(`pathname: ${basePath}`); - + console.log(`basePath: ${basePath}`); + // Build the new URL const url = search ? basePath + search : basePath; console.log(`redirecting to url: ${url}`); - + // Redirect to the new URL window.location.href = url;