Recent Comments

  • hongyi: danny, it makes me smile reading ...
  • danny: nah...lazy to play dk cos if i di...
  • danny: Yeah, I thought it was phishing t...
  • Voyagerfan5761: This happened to me, too; everyon...
  • clara: make a dk i play on icecrowne....
  • Mark: Thanks for this, very helpful!...
  • hongyi: babe...what is that? it looks sca...
  • danny: I'm sure it's possible to do a bl...


posted on: 28th October 2008 by danny in Search Engine Optimisation, Web Development

You may have read my previous entry on performing a 301 redirect from Blogger to Wordpress, where I wrote a script that will capture all traffic to your old Blogger site and redirect it to your new Wordpress site. Ideally you’d want to do the 301 redirects from the web server, but unfortunately Blogger doesn’t allow you to do that and thus, you’re left with the client-side solution: Javascript.

First of all, let me clarify briefly on my previous post and inform you what the core strengths of my script are.

  • Client-side redirect will not work without Javascript. Pretty obvious huh? What that means is that search engine crawlers aren’t able to follow the redirect. Nasty limitation in a simplistic sense.
  • Strengths of my script are:
    1. It works.
    2. You need a client-side solution if you’re on Blogger. No other way.
    3. It captures and redirects all traffic from your old site to your new site.

That being said, let me now expand on these two major points: the limitations of search engine crawlers and why is capturing traffic important.

Continue Reading

posted on: 26th July 2008 by danny in Web Development

As promised in my previous post (301 Meta Refresh Redirects: How Google and Yahoo Sees It), I will show you a script I wrote that will handle 301 redirects from Blogger to Wordpress using the meta refresh tag and javascript.

I have tested it on my old blogger (http://dannynsl.blogspot.com) and it seems to have worked fine so far.

There are a few steps you will first need to do.

  1. Install Wordpress on your domain. There should be installation tutorials on the website. I haven’t had time yet to do my own installation tutorial.
  2. Import your Blogger posts into Wordpress. In your dashboard, go to Manage and then Import.
    Wordpress - Import Blogger
  3. Change your permalink structure. In your dashboard, go to Settings and then Permalinks. The Day and name or Month and name settings should work. However, for my script I think Month and name should be safer.

    Wordpress - Permalinks Settings
  4. Use my javascript code just after the start of the <head> tag in your Blogger layout template. Note: Please make sure you do a backup before making changes. The variables that you need to change are old_root_domain and new_root_domain. This script handles redirection of individual posts, monthly archives and yearly archives. Anything else it will redirect to your homepage.
    <script type='text/javascript'>
    /*
     * Written by Danny Ng (http://www.dannytalk.com/2008/07/25/how-to-301-redirect-from-blogger-to-wordpress/)
     * Free to use and distribute but must keep this comment in place.
     */
    var post_regex = /^http:\/\/(www.)?.*\.blogspot\.com\/\d{4}\/\d{2}\//;
    var month_archive_regex = /http:\/\/(www.)?.*\.blogspot\.com\/\d{4}_\d{2}_\d{2}_archive.html/;
    var year_archive_regex = /updated-min=\d{4}/;
    var label_regex = /search\/label\/.+/;
    var old_root_domain = 'http://dannynsl.blogspot.com', new_root_domain = 'http://www.dannytalk.com', tag_url = '/tag/', redirect_suffix;
    
    if (post_regex.test(location.href))
    	redirect_suffix = (location.href.search(/www/i) == 7) ? location.href.substring(old_root_domain.length+4, location.href.length-5) : location.href.substring(old_root_domain.length, location.href.length-5); // -5 to strip .html
    else if (month_archive_regex.test(location.href))
    {
    	redirect_suffix = (location.href.search(/www/i) == 7) ? location.href.substring(old_root_domain.length+4, location.href.length-16) : location.href.substring(old_root_domain.length, location.href.length-16); // -16 to strip _XX_archive.html
    	redirect_suffix = redirect_suffix.replace(/_/g, '/');
    }
    else if (year_archive_regex.test(location.href))
    {
    	redirect_suffix = year_archive_regex.exec(location.href).toString();
    	redirect_suffix = redirect_suffix.replace(/updated-min=/, '/');
    }
    else if (label_regex.test(location.href))
    {
    	redirect_suffix = label_regex.exec(location.href).toString();
    	redirect_suffix = tag_url + redirect_suffix.split('/')[2];
    }
    else
    	redirect_suffix = '';
    
    document.write("<meta content='0;" + new_root_domain + redirect_suffix + "' http-equiv='refresh'/>");
    </script>

If you want to do a 302 redirect equivalent, just change the number in the meta content from 0 to 1 or 2.

Hope this works for you and please let me know if there are any bug issues.

[edit date=26/07/08]

I just fixed the code to accommodate blog addresses with ‘www’ subdomains. As for redirects for labels, I’ll try to update the code for it tomorrow if I have time.

[/edit]

[edit date=27/07/08]

I’ve added a new regular expression to handle labels and also another variable tag_url that points to your permalink structure for tags or categories.

Wordpress - Category, Tag edit

This setting can be found under Setting, then Permalinks and just scroll right down to the bottom. You will need to edit the variable tag_url to what you’ve sent in the permalinks structure. Make sure you add the ‘/’ at the end of it.

I think by default, Wordpress automatically imports posts from Blogger and sets the labels to categories instead of tags. In this case, just set the variable to the category slug name unless you can be bothered to go through all the posts and set them as tags instead.

[/edit]

posted on: 24th July 2008 by danny in Search Engine Optimisation, Web Development

Normally the best practice for 301/302 (permanent/temporary) redirects are through your web server. However, you can only do this if you own your own domain. So what happens when you’re using a free webpage service such as Blogger, Wordpress and Typepad, and you want to do 301 redirects to your new website?

If you’re thinking of doing Javascript redirects, this isn’t highly recommended as Google and Yahoo web crawlers won’t be able to follow the redirects, which will affect the destination’s ranking and indexing.

Although not the best, your next best bet is using the meta refresh tag to do your redirections. It seems that Google recognises meta redirects and Googlebot should be able to crawl to the new page, according to Google’s Webmaster Help Center.

Yahoo’s Search Help also seems to recognise meta redirects and the crawler will be able to follow the redirects.

It appears that a meta refresh delay of 0 or 1 second will be considered as a 301 redirect and anything longer is considered a 302.

I will try to post a javascript solution that will be able to handle redirects from your old website to appropriate pages of your new website this weekend.