evan
evan

Reputation: 964

GitLab Pages custom domain allow www

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.

Upvotes: 15

Views: 4632

Answers (3)

alierdogan7
alierdogan7

Reputation: 840

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)

Upvotes: 0

evan
evan

Reputation: 964

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.

Upvotes: 20

Mr. Hugo
Mr. Hugo

Reputation: 12592

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

Upvotes: 0

Related Questions