vhosts.html.en revision 83ac24b7851b96b187504b65c4c22372d1fd1b6a
83fdc450aa8f79941bec84488ffd5bf8eadab18eAuke Kok<?xml version="1.0" encoding="ISO-8859-1"?>
83fdc450aa8f79941bec84488ffd5bf8eadab18eAuke Kok<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
83fdc450aa8f79941bec84488ffd5bf8eadab18eAuke Kok<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
83fdc450aa8f79941bec84488ffd5bf8eadab18eAuke Kok XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
83fdc450aa8f79941bec84488ffd5bf8eadab18eAuke Kok This file is generated from xml source: DO NOT EDIT
83fdc450aa8f79941bec84488ffd5bf8eadab18eAuke Kok XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
83fdc450aa8f79941bec84488ffd5bf8eadab18eAuke Kok -->
6bb25a058227d89fbbeba6c12873e6f83da5cf94William Giokas<title>Using mod_rewrite for virtual hosting - Apache HTTP Server</title>
83fdc450aa8f79941bec84488ffd5bf8eadab18eAuke Kok<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
f7900e258dfb8ab55f333d02d96f908ca0ea8899Thomas Hindoe Paaboel Andersen<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
f7900e258dfb8ab55f333d02d96f908ca0ea8899Thomas Hindoe Paaboel Andersen<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
f7900e258dfb8ab55f333d02d96f908ca0ea8899Thomas Hindoe Paaboel Andersen<link href="/images/favicon.ico" rel="shortcut icon" /></head>
f7900e258dfb8ab55f333d02d96f908ca0ea8899Thomas Hindoe Paaboel Andersen<body id="manual-page"><div id="page-header">
f7900e258dfb8ab55f333d02d96f908ca0ea8899Thomas Hindoe Paaboel Andersen<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
f7900e258dfb8ab55f333d02d96f908ca0ea8899Thomas Hindoe Paaboel Andersen<p class="apache">Apache HTTP Server Version 2.3</p>
f7900e258dfb8ab55f333d02d96f908ca0ea8899Thomas Hindoe Paaboel Andersen<img alt="" src="/images/feather.gif" /></div>
f7900e258dfb8ab55f333d02d96f908ca0ea8899Thomas Hindoe Paaboel Andersen<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
f7900e258dfb8ab55f333d02d96f908ca0ea8899Thomas Hindoe Paaboel Andersen<div id="path">
f7900e258dfb8ab55f333d02d96f908ca0ea8899Thomas Hindoe Paaboel Andersen<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.3</a> &gt; <a href="./">Rewrite</a></div><div id="page-content"><div id="preamble"><h1>Using mod_rewrite for virtual hosting</h1>
f7900e258dfb8ab55f333d02d96f908ca0ea8899Thomas Hindoe Paaboel Andersen<div class="toplang">
<p><span>Available Languages: </span><a href="/en/rewrite/vhosts.html" title="English">&nbsp;en&nbsp;</a></p>
</div>
<p>This document supplements the <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
<a href="/mod/mod_rewrite.html">reference documentation</a>. It describes
how you can use <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> to create dynamically
configured virtual hosts.</p>
<div class="warning">mod_rewrite is not the best way to configure
virtual hosts. You should first consider the <a href="/vhosts/mass.html">alternatives</a> before resorting to
mod_rewrite.</div>
</div>
<div id="quickview"><h3>See also</h3><ul class="seealso"><li><a href="/mod/mod_rewrite.html">Module documentation</a></li><li><a href="intro.html">mod_rewrite introduction</a></li><li><a href="remapping.html">Redirection and remapping</a></li><li><a href="access.html">Controlling access</a></li><li><a href="proxy.html">Proxying</a></li><li><a href="advanced.html">Advanced techniques and tricks</a></li><li><a href="avoid.html">When not to use mod_rewrite</a></li></ul></div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="section">
<h2><a name="uservhosts" id="uservhosts">Virtual Hosts Per User</a></h2>
<dl>
<dt>Description:</dt>
<dd>
<p>We want to automatically create a virtual host for every user who
has an account on our web server system, without having to create
new VirtualHost sections.</p>
<p>In this recipe, we assume that we'll be using the hostname
<code>www.<strong>username</strong>.example.com</code> for each
user, and serve their content out of
<code>/home/<strong>username</strong>/www</code>.</p>
</dd>
<dt>Solution:</dt>
<dd>
<div class="example"><pre>
RewriteEngine on
RewriteCond %{<strong>HTTP_HOST</strong>} ^www\.<strong>([^.]+)</strong>\.example\.com$
RewriteRule ^(.*) /home/<strong>%1</strong>/www$1
</pre></div></dd>
<dt>Discussion</dt>
<dd>
<div class="warning">You will need to take care of the DNS
resolution - Apache does
not handle name resolution. You'll need either to create CNAME
records for each hostname, or a DNS wildcard record. Creating DNS
records is beyond the scope of this document.</div>
<p>Parentheses used in a <code class="directive"><a href="/mod/mod_rewrite.html#rewritecond">RewriteCond</a></code> are captured into the
backreferences <code>%1</code>, <code>%2</code>, etc, while parentheses
used in <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> are
captured into the backreferences <code>$1</code>, <code>$2</code>,
etc.</p>
<p>
As with many techniques discussed in this document, mod_rewrite really
isn't the best way to accomplish this task. You should, instead,
consider using <code class="module"><a href="/mod/mod_vhost_alias.html">mod_vhost_alias</a></code> instead, as it will much
more gracefully handle anything beyond serving static files, such as any
dynamic content, and Alias resolution.
</p>
</dd>
</dl>
</div></div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="/en/rewrite/vhosts.html" title="English">&nbsp;en&nbsp;</a></p>
</div><div id="footer">
<p class="apache">Copyright 2009 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div>
</body></html>