DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 5.16 Turning Directories into Hostnames

Problem

You want to migrate pathnames under a single hostname to distinct hostnames.

Solution

Use RewriteRule in httpd.conf:

RewriteRule "^/(patha|pathb|pathc)(.*)" "http://$1.example.com$2" [R]
RewriteRule "^/([^./]*)(.*)" "http://$1.example.com$2" [R]
RewriteRule "^/~([^./]*)(.*)" "http://$1.example.com$2" [R]

Discussion

The first recipe redirects requests of the form http://example.com/pathseg/some/file.html to a different host, such as http://pathseg.example.com/some/file.html, but only for those requests in which pathseg is patha, pathb, or pathc.

The second recipe does the same thing, except that any top-level path segment is redirected in this manner.

The third recipe splits the difference, redirecting all "user" requests to distinct hosts with the same name as the user.

See Also

    [ Team LiB ] Previous Section Next Section