Mobile app version of vmapp.org
Login or Join
Chiappetta492

: How can I redirect both HTTP and HTTPS for a domain hosted on 1and1 to GitHub? I recently bought a domain from 1and1. I then redirected it to my GitHub page, (e.g., http://example.com to https://foo.github.io)

@Chiappetta492

Posted in: #1and1 #Domains #Github #Redirects

I recently bought a domain from 1and1. I then redirected it to my GitHub page, (e.g., example.com to foo.github.io) using 1and1's Domain Center (see the screenshot below):



Now I need to redirect my domain from example.com to example.com so that HTTPS will redirect to my GitHub page. How can this be done?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Chiappetta492

1 Comments

Sorted by latest first Latest Oldest Best

 

@Carla537

This is what I understand:

You have a github page foo.github.io

Your domain example.com is redirected to foo.github.io via an A Record with github-provided IP Address. By this, when using URL example.com, the address bar shows example.com, but data is from foo.github.io. Essentially, example.com & foo.github.io show same page.

Now, github's nature is that it supports both http and https; means if you request http on example.com, it will serve example.com, and if you request https, it will serve example.com (provided your SSL certificate keys are there in github).

What you are asking is that no matter if http was requested or https, only https should always be served.

Now, in dynamic languages and servers like ASP.NET or PHP or LAMP, it would be done server side, but as github support only static html javasçipt css files only, your only option is to use a javascript location.href.replace by detecting if protocol is http, redirect to https.

As I am on mobile and about to board a flight, I will quote javascript code from s similar question's this answer:

if (location.protocol != 'https:')
{
location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
}


Note: If you have never setup SSL Private and public keys for example.com in 1&1's system, it means you first need to do that, otherwise when example.com will be requested, browsers will show an error. I will add some steps for that when I am back from vacation..

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme