7

I have build a website for github pages with jekyll. I setted it up and everything seems to be fine, and my custom domain www.domain.tld is working. But when I enter domain.tld in the browser, it loads for an infinite time. Now I want to redirect the-non www-URL to the www-URL but since I don't have a editable htacces File on Github pages I don't know how to do this.

Nikurasu
  • 71
  • 1
  • 3

3 Answers3

8

There is a generic method to do that.

For example, my github repo is: wpfgeek.github.io.

1. Edit CNAME file in your repository

wpfgeek.github.io/CNAME

www.geekzl.com

2. Enable the https in the settings of the repo

Go to the setting page of the github repo, find the Enforce HTTPS under "Github pages", then tick the checkbox before Enforce HTTPS.

geekcl.com - Enable the https

3. Update DNS Settings in DNS provider

Open DNS provider, add two records like below:

---------------------------------------------
| Record | Record Type | Value              |
| ------ | ----------- | ------------------ |
| @      | A           | 185.199.108.153    |
| ------ | ----------- | ------------------ |
| www    | CNAME       | wpfgeek.github.io. |

Then the site https://geekzl.com and http://geekzl.com will be redirected to https://www.geekzl.com successfully.

You can replace www.geekzl.com to your domain with the prefix www, then replace the CNAME record of wpfgeek.github.io to your repo name.

May it be helpful for you, just enjoy!

Bravo Yeung
  • 8,654
  • 5
  • 38
  • 45
  • I noticed that your CNAME changed to web.geekzl.com, did the other configuration steps change? – Julio Dec 18 '20 at 23:49
  • @Julio The method in this answer is still valid. Currently this site changed because of my personal needs, it is not deployed in github.io now. – Bravo Yeung Dec 19 '20 at 13:28
  • The same should work for subdomains, but you should define both as CNAME record types pointing to USERNAME.github.io – victor.ja Dec 23 '20 at 20:24
  • @BravoYeung What if I want to access the site at [example.com](https://example.com) and redirect [www.example.com](https://www.example.com) to [example.com](https://example.com)? – dryleaf May 15 '22 at 05:46
  • For anyone struggling with a missing SSL certificate on the root domain: I Followed the instructions above for https://www.flyde.dev, but it ended in an SSL error as "flyde.dev" had no certificate. To fix that, I changed the domain on Github's end to be "flyde.dev", which triggered an SSL certificate creation, and then switched back to "www." and everything is working now! – GabrielG Feb 19 '23 at 12:12
4

It depends on the domain hosting service you bought your custom domain from (Google Domains, Domain.com, etc...). You'll have to look in the settings and try to find something like "subdomain forwarding" or "domain forwarding". The wording depends on each service.

The service should have a settings that allow you to forward nikurasu.xyz to www.nikurasu.xyz with settings like Temporary redirect (302), path forwarding, Enable SSL. These are examples from Google Domains, which is my hosting service.

Ultimately, the www forwarding is all done with the domain hosting service and has nothing to do with your GitHub repo or GitHub settings.

DC.Azndj
  • 1,346
  • 12
  • 13
1

Further to @DC.Azndj answer, and applicable only to Google Domains.

The option is in Website menu and not in DNS. This is somewhat confusing if you are familiar with DNS.

Use the option "Add a forwarding address".

By default Google adds two names example.com and www.example.com. If you are forwarding within the same domain, from example.com to www.example.com, you need to edit and remove www entry.

In advanced options you can enable forwarding both SSL and non-SSL ports.

There are few other useful options like path forwarding etc.

Vasu Inukollu
  • 120
  • 1
  • 3
  • 10