How can I redirect both HTTP and HTTPS for a domain hosted on 1and1 to GitHub?

How can I redirect both HTTP and HTTPS for a domain hosted on 1and1 to GitHub? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the How can I redirect both HTTP and HTTPS for a domain hosted on 1and1 to GitHub? error on your web browser. Problem :


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) using 1and1's Domain Center (see the screenshot below):



enter image description here



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


Solution :

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 http://example.com, and if you request https, it will serve https://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 https://example.com will be requested, browsers will show an error. I will add some steps for that when I am back from vacation..


We hope that this article has helped you resolve the domains, redirects, github error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=