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

  • http://httpd.apache.org/docs/mod/mod_rewrite.html



Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net