Building notes, projects, and occasional rants

Virtual hosts via Apple Rendezvous: solution

Just finish writing a hint to MacOS X Hints, about publishing virtual hosts via rendezvous.

Here is a copy, in case it's not accepted. I'm using this as we speak.

In a previous hint it was described how to use the RegisterResource of mod_apple_rendezvous to publish additional paths of your local server via Rendezvous.

Virtual hosts are more complicated because you cannot send the hostname via rendezvous, apparently.

But that's easy to solve with mod_rewrite. To do it, create a file (I named mine virtualhosts.conf) and place it in /etc/httpd/users. Place the following inside:

# you can put anything after /.vh/ as longs as
# it starts with the site name followed by an 
# optional path
RegisterResource "MacOS X Hints" /.vh/
RegisterResource "Send me one, please!" /.vh/

# Add other RegisterResource as above to add more sites

# Magic.....
RewriteEngine On
RewriteRule /\.vh/(.+) http://$1 [R]

and then restart your Apache webserver:

$ sudo apachectl stop
$ sudo apachectl start

You can also restart with sudo apachectl restart or even sudo apachectl graceful. I prefer stop/start.

That's it. Check you Rendezvous menu in the Bookmarks Bar and you'll find "MacOS X Hints" that will redirect to this site.

We can also use this method to support HTTPS. Just add this line to the file:

RewriteRule /\.vhs/(.+) https://$1 [R]

and register resources as:

RegisterResource "Amazon" /.vhs/

We use a prefix, /.vh/ (and /.vhs/), that should be unused in most configurations. If you happen to use it in your own configuration, change all the occurrences to something else, like /.idontusethis/.