转发博主网址以拥有域名网址

时间:2016-01-28 21:31:44

标签: regex redirect blogger url-redirection blogspot

如何将我的blogspot上的所有网址转发到我自己的域名相应的网址? 例如:

转发所有这些:
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
基本上,如何保留网址并将其映射到自己的域名?

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

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

1 个答案:

答案 0 :(得分:2)

三个简单的步骤。

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;