]> granicus.if.org Git - apache/blob - docs/manual/rewrite/vhosts.xml
automatically replace LastChangedRevision
[apache] / docs / manual / rewrite / vhosts.xml
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "../style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="vhosts.xml.meta">
24   <parentdocument href="./">Rewrite</parentdocument>
25
26 <title>Using mod_rewrite for virtual hosting</title>
27
28 <summary>
29
30 <p>This document supplements the <module>mod_rewrite</module> 
31 <a href="../mod/mod_rewrite.html">reference documentation</a>. It describes
32 how you can use <module>mod_rewrite</module> to create dynamically 
33 configured virtual hosts.</p>
34
35 <note type="warning">mod_rewrite is not the best way to configure
36 virtual hosts. You should first consider the <a
37 href="../vhosts/mass.html">alternatives</a> before resorting to
38 mod_rewrite.</note>
39
40 </summary>
41 <seealso><a href="../mod/mod_rewrite.html">Module documentation</a></seealso>
42 <seealso><a href="intro.html">mod_rewrite introduction</a></seealso>
43 <seealso><a href="remapping.html">Redirection and remapping</a></seealso>
44 <seealso><a href="access.html">Controlling access</a></seealso>
45 <!--<seealso><a href="vhosts.html">Virtual hosts</a></seealso>-->
46 <seealso><a href="proxy.html">Proxying</a></seealso>
47 <seealso><a href="advanced.html">Advanced techniques and tricks</a></seealso>
48 <seealso><a href="avoid.html">When not to use mod_rewrite</a></seealso>
49
50 <section id="uservhosts">
51
52   <title>Virtual Hosts Per User</title>
53
54   <dl>
55     <dt>Description:</dt>
56
57     <dd>
58     <p>We want to automatically create a virtual host for every user who
59     has an account on our web server system, without having to create
60     new VirtualHost sections.</p>
61
62     <p>In this recipe, we assume that we'll be using the hostname
63     <code>www.<strong>username</strong>.example.com</code> for each
64     user, and serve their content out of
65     <code>/home/<strong>username</strong>/www</code>.</p>
66     </dd>
67
68     <dt>Solution:</dt>
69
70     <dd>
71
72 <example><pre>
73 RewriteEngine on
74 RewriteCond   %{<strong>HTTP_HOST</strong>}        ^www\.<strong>([^.]+)</strong>\.example\.com$
75 RewriteRule   ^(.*) /home/<strong>%1</strong>/www$1
76 </pre></example></dd>
77
78 <dt>Discussion</dt>
79     <dd>
80
81     <note type="warning">You will need to take care of the DNS 
82     resolution - Apache does
83     not handle name resolution. You'll need either to create CNAME 
84     records for each hostname, or a DNS wildcard record. Creating DNS
85     records is beyond the scope of this document.</note>
86
87 <p>Parentheses used in a <directive
88 module="mod_rewrite">RewriteCond</directive> are captured into the
89 backreferences <code>%1</code>, <code>%2</code>, etc, while parentheses
90 used in <directive module="mod_rewrite">RewriteRule</directive> are
91 captured into the backreferences <code>$1</code>, <code>$2</code>,
92 etc.</p>
93
94 <p>
95 As with many techniques discussed in this document, mod_rewrite really
96 isn't the best way to accomplish this task. You should, instead,
97 consider using <module>mod_vhost_alias</module> instead, as it will much
98 more gracefully handle anything beyond serving static files, such as any
99 dynamic content, and Alias resolution. 
100 </p>
101     </dd>
102   </dl>
103
104 </section>
105
106 </manualpage>