Need help in redirecting WWW to non-WWW in Gitlab Page

I have setup Jekyll, Gitlab page and also added domain for the page. I read here(GitLab Pages settings | GitLab) that Gitlab currently doesn’t support .htaccess so we can’t add redirection. But I was wondering if there’s any other way to redirect from www to non-www version apart from the meta tag redirection method. Thanks!

Did you ever find an solution for this? I am having the same problem

I just added (and verified) another domain in gitlab with the www prepended to it and it seems to have worked.

You can use CNAME record (www) to point to your A record (the site IP).
This is discussed here at Stackoverflow or you need to add www to gitlab pages which is the answer here

I have a solution, demo: https://www.jihu.app and https://jihu.app

steps:

  1. bind www and no-www domain to GitLab Pages
  2. redirect www to no-www in HTML Javascript
  3. add canonical as no-www for SEO in HTML head

code:

<head>
  <link rel="canonical" href="https://jihu.app/">
  <script>
    // gitlab pages doesn't support redirect www to no-www
    if (window.location.host.startsWith("www.")) {
      window.location.replace(window.location.href.replace("www.", ""))
    }
  </script>
</head>