Jul 25 2012

htaccess to Redirect WordPress Blog To Another Domain

If you have an existing WordPress blog that you’ve used for years and have built up some Google juice but now are required to relocate to a different domain, you way want to redirect all the inbound links for the old domain to your new domain. If you still have access to the old existing domain, you can easily redirect all the inbound links to the new domain using the following .htaccess script.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^.*old-domain\.com$ [NC]
RewriteRule ^(.*)$ http://new-domain.com/$1 [R=301,L]

Replace old-domain and new-domain with the correct domain names. If you WordPress blog was located in old-domain.com/wordpress then drop this in the wordpress directory that contains your WordPress installation. Of course, this only works for as long as you have access to the old-domain. Also, be sure to use the same permalink settings in the new WordPress insulation as in the previous so that the redirection maps the blogs posts correctly.

Jul 23 2012

Essential WordPress Plugins

A lot has changed since I last listed my top WordPress plugins. Over the years I’ve been blogging and helping others set up their blogs, I’ve settled on the few must have WordPress plugins that are essential for any new blog.

Jetpack by WordPress
The company behind WordPress, Automattic, have compiled a collection of useful tools that is realized as the Jatpack by WordPress plugin. It’s really a plugin suite. Jetpack includes WordPress statistics right in your dashboard, social sharing widgets, WP.me short/tiny links, and other useful tools. In addition to all these features, Automattic is constantly added more add-ons and tools for this plugin.

Google Analytics
Even though it’s not been updated in a while, I still use Google Analytics so that I can track my sites’ visitors on Google Analytics. Even though the Jetpack by WordPress offers analytics, I’ve find Google Analytics to be more detailed in how it tracks visitors.

Google Sitemap Generator
Any plugin that helps search engines crawl your blog belongs in your toolbox. The Google Sitemap Generator does just that. This plugin creates a search engine friendly site map pointing out the most recent content on your site.

Yet Another Related Posts Plugin
I’ve been using Yet Another Related Posts Plugin for years. I can’t even begin to describe how this plugin works, simple put it magically detects similar blog posts on your site and creates additional links to them in the footer section of your post. This is a great plugin that helps your readers discover other similar posts on your site.

Now that more and more of your visitors are coming to your site using their mobile devices, such as the iPhone or Android phones, you may want to use a plugin like WPtouch. WPtouch creates a mobile device friendly version of your site.

Jul 6 2012

StackOverflow Traffic

There is nothing more that I like than to received a comment to some post I wrote years ago on how it helped someone out. Like this, I’ve come to know that small chunks of code I’ve freely made available are used in production at a variety of sites. It is my hope that the tutorials, examples, and code I write here is of help to others. Even though I like writing tutorials and code to help out my fellow developers, I’ve never answered or posted a question on StackOverflow. My technical blog is really a labor of love and I post around my busy schedule, I’ve never tried to do more than just write about the technology that I use. But even though I don’t use StackOverflow I recently found out from looking at my analytics that I receive a nice amount of visitors from the question and answer site.

StackOverflow Stats

StackOverflow Stats

It always surprises me which posts are the most visited. It’s always the one that you least expect. Either way, I’m always grateful that others have found them useful enough to share on sites like StackOverflow.

Jun 14 2012

Breakdown of Proposed Generic Top Level Domains

ICANN, the organization that regulates domain names, has allowed organizations and individuals to apply for new generic Top Level Domains (gTLD). A Top Level Domain (TLD) is the a domain extension such as .com or .org used by millions of websites. In addition to .com and .org there are country specific TLDs such as .co.uk, .fr, and .mx. ICANN has nearly 2,000 applications for new gTLDs. ICANN has released to the public gTLD application information such as the newly proposed domain extension and the applying company. For example, Google has applied for nearly 100 domain extensions including for .app, .youtube, .goog, .plus, and many more. Google clearly can afford the $185,000/application fee.

I downloaded the data, played around with it and generated some graphs to help me visualize the new land rush for domains. Please note that I discounted and removed a few gTLD applications for non-latin domains.

The first chart shows that nearly 50% of the new domain extension originated from North America. North American and Europe combine make up over 80% while African organization only applied for roughly 1% of proposed new domain extensions.

The following chart shows that a large number of the new proposed generic domain extension are under five characters long but there are a few that are up to eighteen characters in length.

The following graph shows the most popular proposed domain extensions. For example, thirteen different individuals or organizations applied for the .app TLD, eleven for .inc and .home, ten for .art, etc. This chart shows only domains with five or more applications.

As previously noted, Google applied for nearly 100 domain extensions… 98 to be exact under Charleston Road Registry Inc. Top Level Domain Holding Limited registered 68 gTLDs followed by Amazon with 65. Apple doesn’t appear in this chart because this graph shows application organizations with more than ten domain extension applications.

I also wanted to graph the number of applications per primary contact and found out that a single individual, Daniel Schindler, has filed for three hundred domain extensions. Looking at the data, each of the applications submitted by Mr. Schindler are for distinct legal entities.

So who is the real domain squatter? ICANN will be squatting on nearly $400 million because of the $185k/application fee. Another question is, how will a flood of new gTLDs affect the value of current domains? And perhaps most importantly, how will the private organizations use and restrict access to these domain extensions?

Jun 8 2012

JavaScript StackTrace With The console Object

Error handling and debugging had been made difficult in JavaScript because the lack of tools and the language itself. Unlike Java, that has a strong type and hierarchy of exception classes, JavaScript didn’t even have a direct approach to print the execution stack trace. For years I used a workaround to navigate around stack trace of a method call in JavaScript by using the Function arguments property. In JavaScript, all functions have an arguments property defined. The arguments property is available even if the function is defined with no explicit function parameters. The function arguments property behaves like an array and you can iterate through the argument parameters used to call the function but it also has a reference to the caller via the arguments.callee property. The arguments.callee property references the currently executing function itself, which has a caller property to that of the previous function call in the execution stack.

function basicFunction() {
   var isTrue = arguments.callee == basicFunction; // true
   var callingFunction = arguments.callee.caller; 

In the above code, the callingFunction variable holds a reference to the Function object that called the basicFunction.

The caller property returns a Function object or null, so you can chain these until you get to the root of the call stack. You can iterate through a call stack in JavaScript with code similar to the following.

function basicFuction() {
   var caller = arguments.callee.caller;
   while(caller != null) {
      caller = caller.caller;

Unfortunately, there is no clean way to get the function name out of the Function object returned by the caller property. This is made slightly more difficult because somethings functions don’t have names if they are created anonymously. If you print or log a Function object, it displays the function definition in its entirety.

Fortunately, the JavaScript console object provides a trace function that will log to the web console the JavaScript stack trace.

function basicFunction() {

If the above function is invoked from an on click event, the whole JavaScript track trace from the on click to the basicFunction function is logged out in the web console. In addition to the function names, the web console in Safari, Chrome, and Firefox have a link to navigate to the exact location your web application where the functions were called.

Jun 4 2012

JavaScript Debugging With The console Object

In the early days of JavaScript there were few options for debugging large web applications. You could have used the multiple alert notifications or possibly even calling document.write to write messages into the document. Firebug changed web developers lives, and I think how we view JavaScript, by making it incredibly easy to debug HTML, CSS, and JavaScript. Since Firebug, most current versions of web browsers include powerful debugging tools. In addition to the debugging tools browsers have made available a JavaScript console object to help write debug statements. With console, there is no need to pop up alerts to inspect the state of an object. To write a log message intended for the console, just write the following JavaScript statement in the right place.

console.log("This is a log message");
console.log("Message one", "Message two", "Message three");

To open the console, you can find it in Safari by looking for the the Web Inspector, in Chrome it’s called Developer Tools, and in Firefox you’ll find it under the Tools menu as Web Console.

The console object has a lot of useful debugging messages for errors with different severity, such as log, debug, info, warn, and error.

console.info("I'm here.");
console.warn("Do I smell smoke?");
console.error("The roof, the roof, the roof is on fire.");

In addition to logging String messages, you can log whole JavaScript objects. It may be useful to inspect a complete object and it’s state. To write out the state of an object to the console use the dir method as in the following example.

console.dir({fname:"Bill", lname:"Gates"});

In Chrome and Safari, you can also use dirxml to display the a HTML element object in the console as HTML. In my version of Firefox, this method did not work.


You can also group related log messages, no matter their severity. To group console messages surround them with a group and groupEnd. You can even nest groups inside of groups.

console.group("Server update");
console.log("calling server...");
// ... any number of console log messages.

You can also test the performance of your JavaScript code with time and timeEnd. Both of these methods accept a String label and it needs it needs to be the same value for both methods.

console.time("Process Data");
// ... some time consuming code
console.timeEnd("Process Data");

When the timeEnd method is executed it will generate a message in the log console with the amount of time it took to run the code between the time and timeEnd method.

Chrome Developer Tools Web Console

Chrome Developer Tools Web Console