Situation
An ISP provides customers with free web hosting by providing them with web sites rooted at http://home.isp.com/~username/. This is proving unpopular and the ISP wishes instead to offer http://www.username.isp.com/ without changing how they provide the web space.
Solution
Create a Virtual Server for home.isp.com and configure the home directories functionality to provide web sites rooted at ~username. Next, go to the fundamental configuration settings for the Virtual Server and add an alias of '*' to it, so it will catch requests for www.username.isp.com. Then add a request rewrite script similar to the following:
match IN:Host into $ with ^www\.([^\.]+)\.isp\.com
if matched then
set IN:Host = home.isp.com
set URL = /~$1%{URL}
endif
Explanation
The request rewriter executes the script for each request which is processed by the virtual server created above. For each request, the regular expression matching hostnames of the form www.username.isp.com is executed against the Host header. If that matches, then the regular expression captures the username into the $1 variable. If the regular expression matched, then two more actions are performed:
- The hostname is rewritten to
home.isp.com;
- The URL portion has
/~username prepended to it.