简体   繁体   English

将 Blogger 自定义域帖子重定向到另一个域

[英]Redirect Blogger custom domain posts to another domain

I have a blogger blog on http://blog.example.com and I've moved the blog to a new site using WordPress and set up redirects inside WordPress to redirect blogger posts URLs to new URLs for example: the post on blogger is: http://blog.example.com/2016/12/google.html the post URL on the new site is: https://subdomain.domain.com/google/ I've set redirects inside WordPress to redirect from https://subdomain.domain.com/2016/12/google.html TO https://subdomain.domain.com/google/我在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.htmlhttps://subdomain.domain.com/google/

So all what I want is a code to add in the old blogger blog to redirect each page to another page in the new domain, for example:所以我想要的只是在旧博主博客中添加一个代码,将每个页面重定向到新域中的另一个页面,例如:

Redirects from: http://blog.example.com/2016/12/google.html TO https://subdomain.domain.com/2016/12/google.html重定向自: http://blog.example.com/2016/12/google.html : http://blog.example.com/2016/12/google.htmlhttps://subdomain.domain.com/2016/12/google.html

and http://blog.example.com/2015/11/yahoo.html TO https://subdomain.domain.com/2015/11/yahoo.htmlhttp://blog.example.com/2015/11/yahoo.htmlhttps://subdomain.domain.com/2015/11/yahoo.html

Thanks in Advance!提前致谢!

Locate the tag in the header section and insert the following code after the tag: http://www.yoursite.com/'" /> Replace " http://www.yoursite.com " with the URL of the website to which you want to redirect your blog.找到标题部分中的标记,并在标记后插入以下代码: http://www.yoursite.com/'" /> 将“ http://www.yoursite.com ”替换为要访问的网站的 URL你想重定向你的博客。

Original article 来源文章

Switch from compose to HTML in your post edit and put this code inside the post body.在您的帖子编辑中从撰写切换到 HTML,并将此代码放在帖子正文中。

<script type="text/javascript">
    window.location = 'http://your-external-link';
</script>

Actually it's the first time I publish a JavaScript but I'm open to suggestion,edit,comments ...实际上,这是我第一次发布 JavaScript,但我愿意接受建议、编辑、评论......

The idea is to put the following script in blogger template so it'll redirect automatically the user.这个想法是将以下脚本放在博客模板中,以便它会自动重定向用户。

Do not forget to change the variables googleBaseURL and wordpressBaseURL .不要忘记更改变量googleBaseURLwordpressBaseURL

<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>

Here's a snippets which resume your explanation.这是一个片段,可以继续您的解释。

 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>

Insert the code shown below just after the “” tag in the blogger template after replacing the generalized content to your own in the code below.将下面代码中的通用内容替换为您自己的内容后,在博客模板中的“”标签之后插入下面显示的代码。

<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>

Source 来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM