404 page has a redirect loop in versions 16.1-17.8

Description

The 404 page has a redirect loop in versions 16.1-17.8. Examples:

This is not present on the Hugo site (versions 17.9 or newer).

Let's backport fixes to 17.8 and 17.7 since those are currently in the versions dropdown menu.

Steps to reproduce

  1. Visit a 404 page on an online archive prior to 17.9.

Actual result

Redirect loop.

Expected result

No redirect loop.

Further details

This is due to this JavaScript file: https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/content/frontend/404/archives_redirect.js?ref_type=heads. This code should be adjusted to only run on docs.gitlab.com, never the archives domain.

Edited by Sarah German