Get it All

Note: this has been cross-posted to 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 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 ““-style URLs, you get “”

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 “” to “; 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} ^ [nc]
rewriterule ^(.*)$$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 “” and “” 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 “” and clicks on an AJAX-enabled link that points to “,” 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 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!!