Setting up wildcard domains on local host (OS X 10.5)?

Andrew Ryno picture Andrew Ryno · Mar 26, 2009 · Viewed 7.6k times · Source

I am starting to develop a site which basically acts as WordPress MU, in the sense that a user can signup and have their own blog. I will be coding this in Rails, however I am hoping to be able to utilize wildcard subdomains, so I can use the format such as blog.example.com. I've done some searching but I can't find any good resources.

Since I am using Rails, I'm not sure where to put this, as I am using Mongrel, and not Apache. I can bypass doing this on my local machine by developing remotely on my server, however I would only like to keep this as a last resort.

I can give more details about my development environment if needed, but here are the basics:

  • Mac OS X Leopard 10.5.6
  • Ruby 1.8.7
  • Rails 2.3.2

Answer

Nick Hildebrant picture Nick Hildebrant · Mar 26, 2009

Strictly speaking, it's not possible to do that in the hosts file (at least on OS X). It's possible to simulate the behavior with Firefox by configuring it to use a proxy autoconfigure script.

Create a file with the following javascript (I use ~/.proxy.pac)

function FindProxyForURL(url, host) {
  if (shExpMatch(host,"*.<YOUR_DOMAIN>")) {
    //alert("proxy local")
    return "PROXY localhost";
  }
//alert("proxy direct")
return "DIRECT";
}

Then in Firefox > Preferences > Advanced > Network > Settings... > Automatic Proxy Configuration URL:

file:///Users/USERNAME/.proxy.pac

Never tried it in Safari, but it supports PAC files also, so perhaps it works...

The only other alternative I know is to set up a full blown DNS server on your PC...