Skip to content

Support the `force` option (shadowing) in _redirects

Summary

GitLab Pages doesn't currently support Netlify's force option in _redirects. This is called out in the docs here: https://docs.gitlab.com/ee/user/project/pages/redirects.html#files-override-redirects.

It would be great to add support for this configuration option! In particular, this would make it possible to point multiple domains at a single Pages site and have all secondary domains redirect to the primary, canonical domain.

I recently migrated my website to GitLab Pages, and getting the domains to redirect correctly was a bit of trick. I wrote up my experiences here: https://nathanfriend.com/2024/10/14/gitab-pages-with-multiple-domains.html

The tl;dr is that it's not possible to set up a single Pages site with redirects like this:

# Redirect all requests to .io and .dev to .com
https://nathanfriend.io/*  https://nathanfriend.com/:splat 301
https://nathanfriend.dev/* https://nathanfriend.com/:splat 301

because a request to https://nathanfriend.io/hello.html will prioritize returning hello.html with an HTTP 200 over processing any redirect rules.

The workaround that I describe in the post above is to create a second Pages site with no content and contains all the desired _redirects. This works, but it's kind of clunky. It would be nice to have all this configuration live in the main repo; this would be possible with force support.

Example Project

Here's the workaround project I described above: https://gitlab.com/nfriend/nathanfriend.com-redirector/

Technical difficulties

It's been a little while since I last worked with GitLab Pages, but if I remember correctly, the _redirects file is only read and parsed after a request fails to match a file. In order to support the force option, the _redirects file would need to be read and parsed on every request, which might have performance implications.

Edited by Nathan Friend