Partial domain redirection with Apache

Most web hosting services, even the free ones, are a lot faster than your home computer can be, but they often lack the flexibility you want, for example to support cgi-bin scripting.

If you use Apache to host a domain on your home computer, you can redirect the static part of your website (including the pictures!) to an external web server and service the rest on your own computer, with something like this:

	ScriptAlias /cgi-bin/ /var/www/gay/cgi-bin/
	DocumentRoot /var/www/redirect.php

This configuration redirects normal traffic to another URL through the redirect.php script included below. This is the normal behaviour, overridden only for paths starting with /cgi-bin/ according to the ScriptAlias directive.

To make this scheme work, all script references must be made as a full URL, like this: One way of doing that is to include the following line in the HEAD section of all your static HTML pages:

	<BASE HREF="" TARGET="_top">

To round it up, here is the redirect.php code for this setup:

	<TITLE>Page forwarded by</TITLE>
	<BASE TARGET="_top">

		$redir[''] = '';
		$redir[''] = '';
		$redir[''] = '';

		$new = $redir [$SERVER_NAME] . $PATH_INFO;
		print "<FRAME NAME='Page forwarded' SRC='$new' NORESIZE>\n";


Needless to say, Apache allows far more complicated options. For example, the ScriptAliasMatch directive may well serve you to host certain extensions (such as .php) on your own computer.

This idea is based on the plain redirection services as offered for free by CapiBara and MyDomain; these services don't include this more active approach.

Page maintained by Rick van Rein, comments welcomed.