Wednesday, August 15, 2012

Domain moved

You may have seen that this blog is powered by Blogger. It also used to be hosted at typeint.blogspot.com. But now, i moved it to blog.typeint.com, using a nice little trick.
Blogger has a way to do this. However, it requires certain things on the part of the domain, which i did not have access to (i'm using a free webhost, 000WebHost). So after about 12 hours of playing with code, i finally got it to work.
The old domain redirects here after loading the blog header (sorry; technical restriction of using Blogger).
One problem with this is that some gadgets don't always load. If you get this, just reload the page.

If you want the technical explanation of how i did it, read on. Otherwise, you can simply skip to the comment box.

I started out by doing some research. I found a page explaining how to use PHP and .htaccess to mirror a site. I did the thing it needed, and it was marvelously simple. However, as is usual with Google products, it's way too complicated. Gadgets wouldn't load on the mirror.
So, i went to a different trick. This time, i tried an iframe. With a bit of CSS, it looked pretty good. I added some JavaScript to adjust the size (to perfectly fill the area) and focus (for scrolling).
So far, so good.
Except now it doesn't have a window title... I try accessing the title element through the iframe, but that throws a security error (it's on a different domain, so, no-can-do). So now i resort to PHP. An XML parser fails. A regex works. (Congratulate me on being able to properly format such a regex.) Yay, now all that is working.
What now? Now, i have to get it so that clicking a link from the blog actually changes the URL. So i try a jQuery solution that, when a link is clicked, it will edit the parent window's URL. Nope. For some reason, it doesn't work. (Maybe i forgot $(document).ready(function(){...}). I always do.)
Now i try editing the target attribute of all the links on the page (which is not a speed-of-light process). This works, until it doesn't. It turned out i had tried to optimize it, but i managed to fix it.
One more thing that i wanted to do. I wanted it to edit the URLs of links pointing to the old domain (typeint.blogspot.com). So i simply edited the href attribute. Right? As always, i got the code a drop wrong and needed to play with it.
There was one other complication that i had to deal with. Google seems to like to avoid stressing out their servers too much, so they redirect you from the .com to a country based server. For me, this meant typeint.blogspot.com went to typeint.blogspot.co.il. This provided a bit of difficulty in testing the domain, and more importantly, changing links. I did come up with a regex (wow, so many regexes for me!) to solve it, so, all's well.

But now, it's all working!

If anyone wants the code for this, they can head over to my post on Coders' Shed (a programmers' forum) with the code.

3 comments:

  1. Do you also speak English? Yikes!!!! I read it but I'm clueless about WHAT it says!

    ReplyDelete
  2. Do you also speak English? Yikes!!!! I read it but I'm clueless about WHAT it says!

    ReplyDelete