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/
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
and http://blog.example.com/2015/11/yahoo.html
TO https://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.
Switch from compose to HTML in your post edit and put this code inside the post body.
<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 ...
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
.
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.