Skip to content

Redirects

Fernando Lucchesi edited this page May 23, 2022 · 6 revisions

Same domain redirects

Redirects are handled through the Sanity CMS by creating a new redirect document. All redirects created are permanent redirects. To create a new redirect:

  1. Type in the old slug without the domain, starting with /, in the From field. Example: /this-is-an/example
  2. In the To field, select the Page that the redirect should link to

Redirects TO a different domain

Redirects to a different domain are handled in Sanity, under the Settings > External Redirects menu item.

Redirects FROM a different domain

Different domain redirects are handled in the DNS and in the code.

There is a dedicated team responsible for doing so, and this can be request by creating a new ticket in 'service now'.

If an external redirect should be redirected to a specific slug, the logic also needs to be added to the code at: https://github.com/equinor/energyvision/blob/main/web/common/helpers/redirects.ts

Automatic redirects

All slugs ending with .html are automatically permanently redirected to the same slug without the .html. Example: /this-is-another/example.html is automatically redirected to /this-is-another/example

All slugs starting with /news that do not exist in Sanity are redirect to (fallbacks to) /news/archive

All slugs that aRe NoT LoWeRCaSed (except slugs from archived news) are redirected to its lower cased version.

Code implementation

The whole logic is implemented in the file _middleware.ts. In the future we should look into refactoring/moving this logic into next.config.js for performance reasons.