regex - 将博主网址转发到自己的域网址

标签 regex blogger redirect 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
基本上,如何保留 url 地址并将其映射到自己的域上?

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

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

最佳答案

三个简单的步骤。

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; 

关于regex - 将博主网址转发到自己的域网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35072458/

相关文章:

java - 使用java正则表达式解析json数据

css - 向代码框添加水平滚动

zend-framework - Zend 框架 : How to POST data to some external page (e. g。外部支付门)不使用表格?

html - 有限的博客文章出现在主页和标签搜索中

html - 如何在网格中错开照片?

apache - 将所有 HTTP 请求(非 www 和 www,子域)重定向到 HTTPS

redirect - Liferay Portlet和JSF : Redirect during Render Phase

c# - RFC 4180 的 CSV 正则表达式 (C#)

php - 查找具有特殊字符的字符串的最后一个单词

python - 正则表达式用括号外的逗号分割字符串,并具有多个级别的python