将Github页面重定向到自定义域 [英] Redirect Github Pages to custom domain

查看:89
本文介绍了将Github页面重定向到自定义域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Github Pages站点,并将其放在用户名xyz的github帐户的存储库abc中.因此,我的网站现在位于xyz.github.io/abc我使用自定义域创建了一个cname文件,并使用Gi​​thub页面上所述的设置配置了DNS.现在,我的网站也位于mycustomdomain.com上现在,我不希望我的网站位于xyz.github.io/abc上.我希望它重定向到mycustomdomain.com或无法访问.有什么办法吗?我知道我可以创建用户页面站点(使用username.github.io),该站点将自动重定向到自定义域,但是我想创建项目站点.有什么建议吗?

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?

推荐答案

CNAME解决方案:

好的.Github具有很好的功能.
当您在仓库中创建 CNAME 文件夹时,您将被重定向: https://help.github.com/articles/将一个cname文件添加到您的存储库/

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/

查看我的Github Pages网站: https://github.com/ondrek/ondrek.github.io
(您可以浏览 ondrek.com ,但是无法浏览

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 )


JS解决方案:

如果您要重定向自定义页面-唯一可能的解决方案是javascript重定向.

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"; 
}

,但无法解决您在Google上遇到的问题.您可以使用Google网站站长工具正确解决此问题,并将重复的信息告知Google(出于SEO的目的).

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).

这篇关于将Github页面重定向到自定义域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆