Not so long ago I wrote about my experiences on getting Railo running on under OS X as a test. Along with just getting Railo running as well as a custom CMS I needed to be able to proxy requests through an Apache server to the Railo application server. One method is to use the simple mod_proxy module available as part of Apache. In my setup I wanted a bit more control than what mod_proxy could provide me. Enter mod_rewrite.

Mod_rewrite is used to manipulate URLs as they enter and pass through Apache. One way mod_rewrite is useful is that it allows you to rewrite incoming URLs so that what the user sees in their browser’s location bar is translated into what the application expects. You can also use it to manipulate the URL in the event that the location of an object has changed. In my setup I wanted to use mod_rewrite to rewrite certain URLs and then proxy them through the Railo application server.

Lets say my Railo application lives at http://localhost:8080/ and I want any URL that comes into Apache (on port 80) that starts with a keyword like ‘show’ to be rewritten and passed to Railo. Railo could just as easily be hosted on some other machine but for this example lets just say it is located on the same system as Apache.

In my example, I have a new vhost configured in Apache and it looks like this:

  <VirtualHost *:80>
    ServerName railo.dustinrue.com
    DocumentRoot "/Users/dustin/Sites/railo.dustinrue.com"
    <Directory "/Users/dustin/Sites/railo.dustinrue.com">
      RewriteEngine On
      RewriteRule ^show/(.+)$ http://localhost:8080/index.cfm?url=/show/$1} [P]
    </Directory>
  </VirtualHost>

Notice that I’ve told mod_rewite that I want to use an external command for rewriting the incoming URL. An external program basically accepts one argument, which is the URL portion that matches the rewrite rule, and then prints out the reformatted URL which Apache then uses from that time on and in this case, passes to Railo.

In this example, mod_rewrite will take a URL that might look like:

http://railo.dustinrue.com/show/article/id/123456/

And turn it into:

http://localhost:8080/index.cfm?url=/show/article/id/123456/

At the end of the mod_rewrite rule you see a flag telling mod_rewrite to proxy the request through the rewritten URL rather than giving than than telling the browser to visit the new URL (the default behavior). In turn, the request comes into Apache which sees the ‘show’ keyword. This keyword causes the request to be passed to the application server which responds with the appropriate output and this output is then sent to the browser.

In my example, the rewrite is very simple. You can do far more advanced stuff than this and it’s even possible to do some rewriting right within Railo and the server it is running under such as Jetty or Tomcat.

I have two keyboard shortcuts that I just found. Keyboard shortcuts are of course always shown in the menus of applications but I thought I’d mention these two.

Here’s the first one. If you have a folder as a stack item on your dock, command clicking it will immediately open the folder instead of doing the usual stack animations.

The second one is, if you select a file anywhere on the desktop or in a finder window and press command+shift+T you’ll add that item to the dock as a direct link to that file or as a stack if it is a folder. Command+T itself will the selected file as a sidebar item in Finder.

For some reason I decided to give Railo a try tonight. Railo is dubbed as “the fastest CFML OSS engine” available. The little bit that I’ve messed with it so far, I really can’t confirm that. What I can say however is that setting it up is fairly easy, particularly if you choose to download the express package.

One thing that hung me up though, and seems to hang up some others, is the configuration of virtual hosts when using Jetty. The OS X package is only available with Jetty and the documentation does a fine job of explaining how to setup virtual hosts. The only problem is they fail to mention that you actually need to uncomment some of the included config file to make virtual hosts work properly. Some people might see that right away, I glossed over it.

Documentation for setting up virtual hosts is provided by the Railo team at http://www.getrailo.org/index.cfm/documentation/installation/railo-express/. Note that in the virtual host definition section the documentation shows the option virtual host information already commented out, in the files distributed in Railo Express, they are not uncommented.

You can learn more about doing virtual hosts using Jetty at http://docs.codehaus.org/display/JETTY/Virtual+hosts.

One of the things that makes the Mac great is how easily it can find network resources. Apple calls this technology Bonjour but in reality it’s a combination of a number of different protocols talked about at http://www.zeroconf.org/. Avahi is in basic terms an open source implementation of Bonjour and with it you can advertise services that a Linux server provides on your local network. I use Avahi to advertise the netatalk/afp service running on my home Linux system. By doing so, my Linux system shows up immediately in the Finder Window of all of my Macs in the house.

The only “problem” I had was that my Linux system would show up with an icon that looked like an Apple display. I wanted to appear in my Finder window as a little bit closer to reality. By default OS X is aware of all of Apple’s products and can display the appropriate icon for any product it finds. In my setup I’m happy with my Linux system appearing as an older style of PowerMac. With a bit of effort you can cause OS X to show any custom made icon you want.

This blog post explains the process and this comment describes the various device types you can specify.

Since about 2005, Apple laptops have had a feature that allows the laptop to sleep and wake quickly, but also be able to deal with the situation where the battery runs out of power or is removed. Basically the laptop writes out a hibernation file before going to sleep but then doesn’t actually enter hibernation. If the laptop is able to it will simply wake quickly from ram and mark the hibernation file as old. If the battery runs out of power or is remove, then the laptop will boot from the hibernation file instead. This is a fantastic feature because it nearly guarantees you won’t lose work if you’ve put your laptop to sleep.

There are times however that you might not want to use this feature. For example, I was out of town this weekend and my Macbook was spending a lot of time in sleep. Even though sleep uses very little power, it still uses more than it would if the power was completely off. In this situation I prefer that the laptop simply hibernate when I close the lid.

You can tell an Apple portable what kind of sleep mode to use using the command line tool called pmset or, better yet, you can use the very simple preference pane called SmartSleep. SmartSleep is a simple frontend to the pmset command allowing you to choose between a number of different sleep options. Best of all the utility is free and is available at http://www.jinx.de/SmartSleep.html

It’s possible to create a keyboard shortcut to nearly any menu item for any application. For example, lets say you’d like to create a keyboard shortcut to show extensions in Google Chrome.

To do so start System Preferences from the Apple menu in the upper left. Next, click the keyboard option and then click the Keyboard Shortcuts button.

Click the plus to add a new keyboard shortcut. Search for the application, enter in the name of the menu item, the keyboard shortcut you want to assign and click Add.

The shortcut will now have been added. You may need to close and reopen the application before it appears.