Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A solution for virtual hosts and Rendezvous Network
A previous hint described how to use the RegisterResource feature 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.

First, 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]
Next, 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, though. That's it. Check your Rendezvous menu in the Bookmarks Bar in Safari, and you'll find a "MacOS X Hints" entry 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/.
  • Currently 2.75 / 5
  You rated: 5 / 5 (4 votes cast)

A solution for virtual hosts and Rendezvous | 4 comments | Create New Account
Click here to return to the 'A solution for virtual hosts and Rendezvous' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A solution for virtual hosts and Rendezvous
Authored by: fbitterlich on Aug 23, '04 02:45:31PM

Cool tip! However, I can't get the rewrite rule working. The Rendezvous part works fine.
I've set the RewriteLogLevel to 3, but none of the /.vh/ requests seem to go to the rewrite engine... however in other parts of the server I've got reqriting working fine (through a .htaccess file)... any ideas?

[ Reply to This | # ]
A solution for virtual hosts and Rendezvous
Authored by: Beernd on Aug 24, '04 04:10:42AM

I had the same problem when trying to play with mod_rewrite. You need to loosen the tight AllowOverride directive. I just made it as loose as possible: AllowOverride All, and then it worked for me. I'm not sure where exactly it should be placed in this example, I'm no Apache-guru. Just try, I guess you'll be able to make it work.

"Perhaps nothing is quite true, and not even that!"
Multatuli, Ideen 1

[ Reply to This | # ]
A solution for virtual hosts and Rendezvous
Authored by: bluehz on Aug 23, '04 07:07:43PM

I have been playing around with Apache2 I built from scratch and was wondering if anyone knew how to get the same Rendezvous functionality in Apache2 - since Apache2 does not support mod_rendezvous.

[ Reply to This | # ]
A different approach
Authored by: babbage on Aug 25, '04 01:05:34AM

I stumbled upon the RegisterResource trick last week while reading O'Reilly's Mac OS X Panther Hacks, but their approach depends on two Apache directives for each rule you want to set up -- one with the RegisterResource line, and another with a Redirect statement. I came up with a different approach to publishing URLs that aren't on my server that only requires one Apache rule per published URL.

First, you need a CGI script that takes a URL as an argument and responds with an HTTP directive to go to that URL. Here's one way to do it:

$cat ~/Sites/
#!/usr/bin/perl -T

use strict;
use warnings;
my $url = $ENV{'QUERY_STRING'} || "http://some/default/page/";

print "Location: $url\n\n";

$ ls -l ~/Sites/
-rwxr-xr-x    1 www      www           337 Aug 24 20:37 /Users/you/Sites/
$ ~/Sites/ 
Location: http://some/default/page/


If you can get similar behavior as what I show above, you're most of the way there. If you don't like Perl, this script could probably be rewritten in PHP, and can certainly be done in Python or even a Bourne shell script, but I do like Perl, and this was easy to do and I already have my Apache set up to serve mod_perl. YMMV.

Once you have the redirect script in place, set up as many offsite redirects as you want, prefixing them with this redirect script's relative URL, like this:

RegisterResource "Some name" /

Restart Apache and everything will work just fine. Bouncing through your little script should be fast (most users shouldn't notice the delay), and as a bonus (if you're in to this sort of thing) you get a record of the activity in your Apache log.

Not that there's anything wrong with this <virtualhost> idea, but it seems a lot more complicated than doing it this way... :-)


[ Reply to This | # ]