GitLab Pages custom domain allow www
Asked Answered
L

3

15

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.

Luker answered 5/9, 2016 at 15:56 Comment(0)
L
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.

Luker answered 7/9, 2016 at 16:36 Comment(4)
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...Apicella
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 <repo>.gitlab.io. Now it's good, thanks!Maggy
So it's not possible to just add a CNAME for www as an alias of mydomain.com?Panoptic
GitLab Pages docs section Redirecting www.domain.com to domain.com with Cloudflare recommends a 301 redirect (Page Rules in CloudFlare)Withhold
A
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

Apicella answered 5/9, 2016 at 22:0 Comment(3)
Unfortunately I get this error when I try to create the subdomain with www, any ideas?Luker
won't solve the issue, it is a DNS misconfiguration. Redirection on the client side would not solve it.Disenthral
Glad you figured it out!Apicella
B
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)

Blueing answered 2/1, 2021 at 7:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.