热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

将Github页面重定向到自定义域-RedirectGithubPagestocustomdomain

IhavecreatedaGithubPagessiteandputitonrepositoryabcofgithubaccountwithusernamexyz.

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?

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

2 个解决方案

#1


A CNAME solution:

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有一个很好的功能。当您在回购中创建CNAME文件夹时,您将被重定向: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 )

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


A JS solution:

一个JS解决方案:

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

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

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

但它无法解决您的问题。您可以使用Google网站站长工具正确解决此问题,并告知Google有关重复的内容(用于搜索引擎优化目的)。

#2


You could use Javascript to inspect the domain of the current page and redirect if necessary. If you go this route, the question and answer are already on SO:

您可以使用Javascript检查当前页面的域,并在必要时重定向。如果你走这条路,问题和答案已经在SO:

Redirection based on URL - Javascript

基于URL的重定向 - Javascript


推荐阅读
author-avatar
明睿崇
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有