Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect Github Pages to custom domain

I have created a Github Pages site and put it on repository abc of github account with username xyz. So, my site is now live on xyz.github.io/abc I created a cname file with my custom domain, and configured my DNS with the settings said on Github pages. Now, my site is also live on mycustomdomain.com Now, I don't want my site to be live on xyz.github.io/abc . I want it to redirect to mycustomdomain.com or not accessible. Is there any way to do that? I know that I can create User Pages site (with username.github.io) which will automatically redirect to custom domain, but I want to create project site. Any suggestions?

like image 216
manish Avatar asked May 11 '15 11:05

manish


People also ask

Does GitHub Pages support custom domain?

You can customize the domain name of your GitHub Pages site. GitHub Pages is available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.

Is custom domain free GitHub Pages?

GitHub Pages is just the solution to that problem. It's free. You can host your website, including custom domain names(https://dhrumil.xyz), 404 error page, sub-domain (https://blog.dhrumil.xyz) and all over secure https.

Can I use GitHub Pages to host website?

You can use GitHub Pages to host a website about yourself, your organization, or your project directly from a repository on GitHub.com.

Can GitHub Pages host dynamic website?

GitHub Pages doesn't support dynamic websites or anything requiring a backend or secret data. There are other sites that provide this kind of hosting, such as Netlify and Heroku, along with many others.


1 Answers

A CNAME solution:

Sure. Github has a nice functionality for it.
When you create CNAME folder inside of your repo, you will be redirected: https://help.github.com/articles/adding-a-cname-file-to-your-repository/

Check out my Github Pages website: https://github.com/ondrek/ondrek.github.io
( you can browse ondrek.com, but it's impossible to browse ondrek.github.io )


A JS solution:

If you want to redirect a custom page — the only possible solution will be javascript redirection.

if (window.location.href==="https://xyz.github.io") {
    window.location.href = "https://mycustomdomain.com"; 
}

but it will not solve your problem with Google. You can solve this with correct using Google Webmaster Tools and tell to Google about the duplicate (for SEO purposes).

like image 164
Samuel Ondrek Avatar answered Dec 19 '22 10:12

Samuel Ondrek