Get it All
Together

One point I did not mention on the other blog, which is definitely an SEO advantage of using the “sans w” address redirect:

Generally, your Pages Per Visit covers your entire website, but when ranking which pages get hit the most, once again www.yostuff.com is different than yostuff.com.  Since Google Webmaster Tools allows you to set a Preferred Domain, it is logical to assume that the form of the domain that the Googlebot crawls is important to how it ranks pages.  In fact, the above-linked blog post more or less spells this out exactly.

So, get out there, set your preferred domain and make sure your server points users in the right direction.  As most of us who’ve been doing this a while can attest, it’s the little things that count.

Note: this has been cross-posted to dragonflyeye.net for the sake of informing my hippie bloggin’ buddies.
OK, so that’s just a humorous side-effect, but funny, nonetheless. . .

Anywho, I’m pretty exited about my latest little tweak to this here website, and I thought I’d share. A very wise personage who runs a site called Corz.org has a fantastic tutorial on the mod_rewrite Apache directive which has been something of a bible to me in the last few months as I endevoured to create the latest version of DFE.

Foremost among his/her tutorials of interest is the two-part examination of the mod_rewrite Apache directive. If you don’t know what that is, you’re not alone. Despite it’s anonymity, it is responsible for the “clean urls” look of WordPress and other modern blog software, where instead of nasty-looking “http://www.somewhere.com/index?file=25%category=stuff%otherthings=things“-style URLs, you get “http://www.somewhere.com/stuff/things/this_is_an_article.”

But that’s long leagues from all that it can do, as you will discover if you read that tutorial. One thing you can do with it, and what I’ve just done, is to use it to redirect reader’s browser from “http://www.yourblog.com” to “http://yourblog.com; regardless of what specific page they request, they will always be directed to a page that does not have the “www.” The directive looks like this:

# Begin rewrite rule: nix the www
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.yostuff.com [nc]
rewriterule ^(.*)$ http://yostuff.com/$1 [r=301,nc]
# End domain rewrite rule

If you wish to incorporate this directive into your site, you simply add it to the .htaccess file on the root of your WordPress blog (and if that’s not the root of your domain, which it isn’t in my case, you’d also need to add it to the root directory). I’ll get more into how it works below, but first to answer an obvious question:

Why would you do a thing like this, you ask? Well, there are a number of reasons. For one, the URL without the superfluous “www” just plain looks nicer and is less bulky. Better yet, this directive will encourage people to use the “sans w” version by visually associating the site with the cleaner URL without annoying people who either chose to use the older style or followed an old link in the older style.

But the biggest reason, for me, was that I needed to assure myself that the host portion of the domain name was always consistent for the sake of implementing AJAX and JavaScript code. Strange as it may seem, even though “www.dragonflyeye.net” and “dragonflyeye.net” are functionally equivalent addresses to users, they are not the same thing to the browser or to JavaScript. One points to a domain and the other points to a specific host on the domain (the server labeled “www”). Technically, those address variations could potentially refer two different hosts altogether.

JavaScript’s “sandbox” security rules prevent code downloaded from one host to execute code on another host. If a user is on “www.dragonflyeye.net” and clicks on an AJAX-enabled link that points to “dragonflyeye.net,” they’re going to get an error message instead of what I intended because they are unknowingly violating that rule.

That’s just bad. Not only bad, but embarrasing as well. But by using this directive, I avoid all that mush. Now, I can confidently code for dragonflyeye.net without worrying that someone might have come to the wrong (but still technically right) address. Even if they have, they will be directed to the correct address.

WordPress users take note: in order to change this directive in your .htaccess file and have it work right, you’re also going to need to change the URL of your site (so that it doesn’t have the “www”) in the “Options” section of your WordPress Admin site. Not to worry: once this is done, you won’t have any problem with older links to your site. That’s the whole point!!