Redirecting Old blog address to a new blog address permanently in blogger
Asked Answered
S

4

10

I'm having a blogger blog and it's custom domain expires in a week. So, I planned to create a new blog and redirect the custom domain to the new blog domain. Consider, my old domain is old-blog.blogspot.com and I wish to redirect all the links to the old blog to my new address new-blog.blogspot.com. So, was there any ways doing it?

As I googled, I read about doing that with blogger conditional statements and that should be done for every post. But, in my blog I've more than 200 posts. Any ways?

Serrate answered 25/4, 2013 at 14:1 Comment(0)
H
12

You could try to use javascript.

Put the following code inside <head> tag in your template.

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

This will redirect user to the new domain and to the same post URL as in old domain.

Hashum answered 25/4, 2013 at 14:56 Comment(4)
This solutions is not working in blogger dynamic views. Should it be something else for that?Mayhew
Can anyone explain regex used?? I'm wanting change it a little bit.Scoutmaster
I'm a wee bit late - but the regex finds everything before the first slash in the site path/page and removes itEndocarditis
for example, it would replace https://google.com/foobar/test.html with foobar/test.html. Then it does http://new-blog.blogspot.com + foobar/test.htmlEndocarditis
D
4

I did a lot of searching for how to migrate my Blogger account so that:

  1. Each blog post at the old URL gets redirected to the same blog post on the new URL (e.g. http://old-url.blogspot.com/bar gets redirected to http://new-url.com/bar).
  2. You do the redirect in a way that doesn't lose SEO rank. This means that JavaScript solutions (e.g. the accepted answer in this post) won't work, as you need a server-side generated <link rel="canonical" href="http://new-url.com/bar"/> tag in the <head>.

I found no satisfying answers, so to help others in the future, I thought I'd add the hack I came up with here. The reason you need a hack is that blogger templates use some arcane XML syntax that allows basic variable lookups, loops, and if-statements, but as far as I can tell, there is no way to do string manipulation to accomplish the URL transformation in requirement #1 above. To work around this, you can generate a hard-coded list of if-statements that check every possible URL you care about and redirect it to the proper place. Something along the lines of:

<b:if cond='data:blog.canonicalUrl == "http://old-url.blogspot.com/url1"'>
  <link rel="canonical" href="http://new-url.com/url1"/>
  <meta http-equiv="refresh" content="0; url=http://new-url.com/url1"/>
<b:elseif cond='data:blog.canonicalUrl == "http://old-url.blogspot.com/url2"'/>
  <link rel="canonical" href="http://new-url.com/url2"/>
  <meta http-equiv="refresh" content="0; url=http://new-url.com/url2"/>
<b:elseif cond='data:blog.canonicalUrl == "http://old-url.blogspot.com/url3"'/>
  <link rel="canonical" href="http://new-url.com/url3"/>
  <meta http-equiv="refresh" content="0; url=http://new-url.com/url3"/>
<!-- And so on, one if-statement per blog post -->

If you can do basic scripting, you don't have to generate these if-statements (and there may be hundreds) by hand. Instead, you can export your Blogger posts to an XML file and write a simple script to read in each URL in that file and generate the if-statement above. I wrote a blog post about migrating from Blogger to GitHub Pages where I explain all the gory details and the Ruby script I used to generate the if-statements is available on GitHub. Note that this is a very hacky script customized for my blog, and it actually runs against the Jekyll conversion of the blogger XML export, but you can use it as a base to create your own script and avoid lots of weird blogger template error messages.

Dealings answered 20/4, 2015 at 17:58 Comment(2)
Thanks. I ended up taking the same path that you did, I just wrote my own blogger template generator as well as the script that simplifies html files and creates md files in F#: gistReversible
Super helpful, thanks. Something else I had to do was set timezone: "America/Chicago" in my _config.yml, otherwise GH Pages would put posts into folders based on UTC, which didn't always match the dates generated by the script. I could also have run the script with TZ="" to match GH Pages, different people will have different opinions about which is more correct.Missilery
U
1

For viewers who might have Javascript turned off (which is rare these days, but not unheard of), you can put

<meta content='0;url=http://your-new-url.tld' http-equiv='refresh'/>

instead.

Or do both :)

Urgency answered 8/3, 2014 at 2:24 Comment(0)
R
0

you must import your blog

click setting and click other and then click impor blog

Next save your result download ( XML file ) and then click your new blog, then click setting then click other then click ekspor blog then upload your result download ( XML file ) finish

Ruthenian answered 10/5, 2013 at 11:17 Comment(2)
That explains only for changing posts from one blog to another but, I asked about redirection.Serrate
<script type='text/javascript'> window.location.replace("your URL") </script>Ruthenian

© 2022 - 2024 — McMap. All rights reserved.