2024-08-20 18:35:47 +00:00
|
|
|
<script>
|
|
|
|
// Check if the current path is versioned, if not, redirect to the default versioned path
|
2024-08-20 19:07:45 +00:00
|
|
|
const versions = ["stable"]
|
2024-08-20 18:56:31 +00:00
|
|
|
const defaultVersion = "stable"
|
2024-08-21 04:47:07 +00:00
|
|
|
const basePath = "en/"
|
2024-08-20 18:35:47 +00:00
|
|
|
const targetRedirectPath = "404" // path to redirect to, relative to basePath
|
|
|
|
|
|
|
|
// if path starts with version, redirect to versioned 404
|
|
|
|
let foundVersion = false
|
|
|
|
versions.forEach(version => {
|
|
|
|
const versionedPath = `${basePath}/${version}`;
|
|
|
|
if (window.location.pathname.startsWith(versionedPath)) {
|
|
|
|
// we need this foundVersion guard because the browser is fast and
|
|
|
|
// will keep the executing code below until the redirect happens
|
|
|
|
foundVersion = true;
|
|
|
|
window.location.href = `${versionedPath}/${targetRedirectPath}`
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// if path doesn't start with any version, redirect to defaultVersion
|
|
|
|
// Replace it in href, so we keep hashes and query params
|
|
|
|
// Only replace first occurence of basePath
|
|
|
|
if (!foundVersion){
|
2024-08-20 19:07:45 +00:00
|
|
|
//window.location.href = window.location.href.replace(basePath, `${basePath}/${defaultVersion}`)
|
|
|
|
window.location.href = `https://${window.location.hostname}/${basePath}/${defaultVersion}`
|
2024-08-20 18:35:47 +00:00
|
|
|
}
|
|
|
|
</script>
|