【问题标题】:Forward blogger urls to own domain urls将博主 url 转发到自己的域 url
【发布时间】:2016-05-06 11:25:44
【问题描述】:

如何将我 blogspot 上的所有 url 转发到我自己域的对应 url? 示例:

转发所有这些:
http://example.blogspot.com/url-1.html
http://example.blogspot.com/url-2.html
http://example.blogspot.com/url-3.html

甚至不存在的网址
http://example.blogspot.com/non-existing-url-4.html

给这些对应自己的域:
http://owndomain.com/url-1.html
http://owndomain.com/url-2.html
http://owndomain.com/url-3.html
http://owndomain.com/non-existing-url-4.html
基本上,如何保留url地址并将其映射到自己的域?

我已经有了,但这只是将 blogspot 的主页重定向到我自己域的主页:

<script type='text/javascript'>
  var d='<data:blog.url/>';
  d=d.replace(/.*\/\/[^\/]*/, '');
  location.href = 'http://owndomain.com';
</script>

【问题讨论】:

    标签: regex redirect blogger url-redirection blogspot


    【解决方案1】:

    三个简单的步骤。

    1) 获取当前 URI:

    var blogSpotURI = window.location.href;
    

    2) 然后将 blogspot 域替换为自己的域:

    var ownDomainURI = blogSpotURI.replace('example.blogspot.com', 'owndomain.com');
    

    3) 然后将浏览器指向新的 URI:

    window.location.href = ownDomainURI;
    

    完整的脚本:

    var blogSpotURI = window.location.href;
    var ownDomainURI = blogSpotURI.replace('example.blogspot.com', 'owndomain.com');
    window.location.href = ownDomainURI;
    

    更新版本

    /* grab URI from browser address bar */
    var blogSpotURI = window.location.href; 
    
    /* remove subdomain and domain */
    var ownDomainURI = blogSpotURI.replace('http://example.blogspot.', ''); 
    
    /* Find position of first forward slash after the TLD */
    var slashPosition = ownDomainURI.indexOf('/');
    
    /* Remove the TLD */
    ownDomainURI = ownDomainURI.substring(slashPosition);
    
    /* Add new domain and new TLD */
    ownDomainURI = 'http://owndomain.com' + ownDomainURI; 
    
    /* Point browser window at new address */
    window.location.href = ownDomainURI; 
    

    【讨论】:

    • 谢谢。它正在工作,但有一个警告。如您所知,blogspot 域会自动更改为该国家/地区的域名(如果存在),因此不会触发重定向,除非我将 example.blogspot.com 更改为 example .blogspot.de 例如,如果用户来自德国。我们如何将 example.blogspot.com 更改为可以考虑任何域结尾的内容?
    • 你是个英雄,希望我能给你更多的帮助!珍贵!
    • 是否也可以为此脚本启用屏蔽选项?在将任何 url 转发到等效的 mydomain url 时,是否可以在 url 地址栏中显示原始 url?我应该把它作为一个新问题吗?
    • 最好将其作为一个新问题发布,是的。
    猜你喜欢
    • 2016-05-08
    • 1970-01-01
    • 2016-11-14
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-12
    相关资源
    最近更新 更多