Skip to content

Redirect all but used subdomains to primary domain using mod_rewrite and CodeIgniter

I was recently playing with mod_rewrite and wanting a couple of subdomains to act as subdomains, but all others to redirect back to my site without the leading “www”. For example:

www.example.com => example.com
bad.example.com => example.com
api.example.com => api.example.com

Not being a regular expression or mod_rewrite expert (or any resemblance of such), this was a bit of a challenge. But I did it with the help of a mod_rewrite and regular expression cheat sheet, as well as the excellent Apache URL Rewriting Guide.

So here it is for anyone else that could benefit. Just replace the bold parts with your own subdomains (and example with your domain).

Redirect without leading www:

Redirect with leading www:

If you’re using CodeIgniter and mod_rewrite for pretty URLs, you’ll need to be sure to add these subdomains to the list of directories that can be accessed directly.

Serving a large file through PHP without hitting memory_limit

Ran into a little problem hitting the memory limit for PHP when serving 100MB+ files through a script like:

Found that you need to call ob_flush() as well as flush() since flush() has no effect on the buffering scheme of your web server.

Just thought I’d throw that out there for anyone else.

MultiTouch Trackpad Gestures For The Rest Of Your Apps

If you’re one of the lucky ones to be able to get one of the latest MacBooks with Multi-Touch, you’ve probably asked the same question I have: “How can I get Firefox to use the swipe gesture to go forwards and backwards like Safari does?”

Answer: MultiClutch

This neat little Preference Pane addition will allow you to associate trackpad gestures with keyboard shortcuts; per application.

So this gives you exactly what you’re looking for: navigation for Firefox 3 (beta) via trackpad gestures. Only apps built with Cocoa are supported right now, so this won’t work with Firefox 2, sorry!

If you found that app useful, please consider making a small donation to Will! It helps make the world go round. =)

Cycle Your Batteries!

MacBook Battery UsageWhen buying portable products, I usually like to be (over) prepared for whatever situation may arrive.  When I bought my Panasonic HD camcorder, I also searched the web thoroughly and bought two extra batteries and a 16GB SD Card.  Plenty of power and plenty of space.

So I found myself looking at an extra battery for my recent MacBook Pro purchase so that I’m never caught dead.  As I do before buying anything electronic over $50 I started reading the reviews, which all seemed to be horrible, dating back to 2005 even.  I was a little confused since I went the entire weekend without having to charge my MacBook Pro, and even found myself on Sunday night waiting for the battery to die before I went to bed so I could give it a full cycle.

MacBook Battery HistoryObviously I didn’t use my notebook more than 5 hours (the rated time it can/should last).  I didn’t do any work this weekend (that’s a first really), so nothing more than looking up movie times, checking bank statements and researching some thing (ok, so maybe I did a little work)… but battery life was more than adequate. So I didn’t quite understand all these reviews; especially some claiming “my battery doesn’t last more than 10 minutes!”.

For any MacBook user, you’ll find a wonderfully cool program called CoconutBattery that tells you the actual and rated battery capacity at any time. (Just don’t leave the application open, I found that it locks up my entire system after prolonged use.) So armed with that, and with Apple’s battery notebook care, you’ll have everything you need to help get the most out of your battery.

As you can see from my battery history, as I started to completely drain my battery (2008-04-04), my battery’s maximum capacity increased. April 06 was when I completely drained and charged the battery for the first time.  I’m willing to bet that many (the “average”?) user doesn’t know or understand how batteries work. They understand (and I remember thinking in my teenage years) that batteries fill up and drain; there’s nothing else to them.

And who knew you could calibrate your battery to ensure an accurate reading?

This is also great advice for anyone using anything that has a battery.  Batteries need to be used to be kept healthy.  Windows users can use tools like BatteryMon (30-day trial, $24) to get battery capacity monitoring and recording.

iPhone users should take this advice to heart also, especially since replacing the iPhone battery is only free within your first year of purchase under the warranty; and that’s only if the battery is holding less than 50% of what it should. Otherwise you’re looking at almost $90 and a week or two without your phone.

In short, use your batteries!

Getting Organized with Spaces

Spaces ImageUpon getting my Mac, Spaces was one of the first things I checked out. I had tried Virtual Desktops in Windows and Linux, but never found them to be too terribly helpful. Not to mention I used a dual monitor setup with my Windows machine, so I felt I had plenty of room for things.

Despite having a nice big 24″ screen, I have often felt my desktop to be cramped and cluttered; especially coming from a dual monitor setup. So the idea of Spaces seemed perfect, except using the keyboard shortcuts felt too slow and like to much work just to get to another application or space. (F8 + Click on a space OR Cmd + Arrow) So this tip from Mac Os X Hints sounded like the perfect solution. Although they don’t actually offer a tip on how to do it (just the tip to do it), this is what I’ve done:

1. Assign Spaces to use the Cmd + Arrow keys too switch between Spaces.
2. Use SteerMouse to assign the right and left mouse scroller to use those combinations (Cmd + Right Arrow) (Cmd + Left Arrow)
3. There is no three!

I’m using 6 spaces now, for web browsing, coding, FTP, RSS Feeds, iChat and iTunes.

Any other suggestions on a good/better way to do the key assigning let me know!