[英]Redirect Blogger custom domain posts to another domain
我在http://blog.example.com
上有一个博主博客,我已经使用 WordPress 将博客移到了一个新站点,并在 WordPress 内设置了重定向以将博主帖子的 URL 重定向到新 URL,例如:博主上的帖子是: http://blog.example.com/2016/12/google.html
: http://blog.example.com/2016/12/google.html
新网站上的帖子 URL 是: https://subdomain.domain.com/google/
: https://subdomain.domain.com/google/
我在 WordPress 中设置了重定向以从https://subdomain.domain.com/2016/12/google.html
重定向https://subdomain.domain.com/2016/12/google.html
到https://subdomain.domain.com/google/
所以我想要的只是在旧博主博客中添加一个代码,将每个页面重定向到新域中的另一个页面,例如:
重定向自: http://blog.example.com/2016/12/google.html
: http://blog.example.com/2016/12/google.html
至https://subdomain.domain.com/2016/12/google.html
和http://blog.example.com/2015/11/yahoo.html
到https://subdomain.domain.com/2015/11/yahoo.html
提前致谢!
找到标题部分中的标记,并在标记后插入以下代码: http://www.yoursite.com/'" /> 将“ http://www.yoursite.com ”替换为要访问的网站的 URL你想重定向你的博客。
在您的帖子编辑中从撰写切换到 HTML,并将此代码放在帖子正文中。
<script type="text/javascript">
window.location = 'http://your-external-link';
</script>
实际上,这是我第一次发布 JavaScript,但我愿意接受建议、编辑、评论......
这个想法是将以下脚本放在博客模板中,以便它会自动重定向用户。
不要忘记更改变量googleBaseURL
和wordpressBaseURL
。
<script type="text/javascript">
var googleBaseURL = 'http://blog.example.com/', // We define what's our blogger URL
wordpressBaseURL = 'https://subdomain.domain.com/', // We define what's our wordpress URL
requestedURL = window.location.href, // We get the URL requested by the user
requestedPage = requestedURL.split(googleBase)[1], // We get the requested page
newURL = wordpressBase + requestedPage; // We create our new URL
window.location = newURL; // We redirect
</script>
这是一个片段,可以继续您的解释。
var div = document.getElementById('message'), googleBaseURL = 'http://blog.example.com/', // We define what's our blogger URL wordpressBaseURL = 'https://subdomain.domain.com/', // We define what's our wordpress URL requested = 'http://blog.example.com/2016/12/google.html', // URL requested by user requestedPage = requested.split(googleBaseURL)[1]; // Requested page by user div.innerHTML = div.innerHTML + "From: " + requested + "<br />"; // Requested url div.innerHTML = div.innerHTML + "The script redirect the user to: " + wordpressBaseURL + requestedPage; // Redirect to this url
<div id=message></div>
将下面代码中的通用内容替换为您自己的内容后,在博客模板中的“”标签之后插入下面显示的代码。
<b:if cond="’data:blog.url" =="“http://your-blog-name.blogspot.com/YEAR/MONTH/BLOG-POST-SLUG.html”‘"><meta content="’0;url=http://yoursite.com/NEW-BLOG-POST-SLUG.html’" http-equiv="’refresh’/"></b:if>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.