Nikurasu
Nikurasu

Reputation: 121

Github pages redirect non www (root domain) to www subdomain

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.

Upvotes: 12

Views: 5650

Answers (3)

Vasu Inukollu
Vasu Inukollu

Reputation: 130

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.

Upvotes: 1

Bravo Yeung
Bravo Yeung

Reputation: 9840

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!

Upvotes: 11

DC.Azndj
DC.Azndj

Reputation: 1396

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.

Upvotes: 5

Related Questions