14

What do I need to do in order for my GitLab pages site (Jekyll) to be accessed under www.mydomain.com not just mydomain.com? I have SSL through CloudFlare.

In my DNS I have: mydomain.com A 104.208.235.32

and CNAME points to myname.gitlab.io, and www points to myname.gitlab.io

Do I need to create a subdomain of www and point those to GitLab as well? I'd like my site to be without www in the url, but if a user types in www they should still be able to access the site.

evan
  • 954
  • 3
  • 18
  • 37

3 Answers3

20

The configurations in the question are correct, what I didn't do is add both mydomain.com and www.mydomain.com as domains in GitLab (Settings icon > Pages > New Domain).

GitLab then directs traffic to both www and the naked domain when both domains are listed.

evan
  • 954
  • 3
  • 18
  • 37
  • 2
    I would choose for www. or the naked domain, and not use both. Duplicate content and split page rank could occur when you use both. Might not be true though... – Mr. Hugo Sep 07 '16 at 20:20
  • 1
    I had this exact problem. I had to set my www domain on git lab pages too (wasn't obvious), then I had to add two A records (one for @ and one for www with the gitlab ip), and then I had to add a CNAME for www to .gitlab.io. Now it's good, thanks! – jbaranski Oct 15 '17 at 14:43
  • 2
    So it's not possible to just add a CNAME for `www` as an alias of `mydomain.com`? – wasabigeek Jun 18 '18 at 14:43
  • GitLab Pages docs section [Redirecting www.domain.com to domain.com with Cloudflare](https://docs.gitlab.com/ee/user/project/pages/getting_started_part_three.html#redirecting-wwwdomaincom-to-domaincom-with-cloudflare) recommends a 301 redirect (Page Rules in CloudFlare) – Leeroy Mar 13 '19 at 15:46
0

Create a subdomain www.example.com and point that to gitlab. Then detect www in the URL and redirect to non-www.

<script type="text/javascript">
if ( document.domain.substring(0,4) != 'www.' ) {
    window.location = document.URL.replace("//","//www."); 
}
</script>

Source: https://www.experts-exchange.com/questions/26846703/redirect-non-www-to-www-url-using-Javascript.html

Mr. Hugo
  • 11,887
  • 3
  • 42
  • 60
0

What worked for me:

Add www subdomain as a separate page to your GitLab pages domains and please follow the instructions in the documentation:

Set up DNS Records for both root and subdomains (www)

alierdogan7
  • 600
  • 7
  • 14