我在
http://blog.example.com
上有一个博主博客,我已使用 WordPress 将博客移动到新站点,并在 WordPress 内设置重定向以将博主帖子 URL 重定向到新 URL,例如:
博主的帖子是:http://blog.example.com/2016/12/google.html
新网站上的帖子网址是:https://subdomain.domain.com/google/
我已在 WordPress 中设置重定向,从 https://subdomain.domain.com/2016/12/google.html
重定向到 https://subdomain.domain.com/google/
所以我想要的只是在旧博客中添加一段代码,将每个页面重定向到新域中的另一个页面,例如:
重定向自:
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”替换为您要将博客重定向到的网站。
在帖子编辑中从撰写切换到 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>
感谢您分享这些宝贵的想法! Teenyfy 有效缩短 URL,将冗长的链接转变为简洁的链接。使用 Teenyfy 简化共享并增强可访问性。免费的网址缩短器自定义域可以轻松简化您的在线交流并有效地吸引您的受众。了解更多请联系我们!