RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
-RewriteRule ^/(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R]
+RewriteRule ^/?(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R]
</pre></div>
<p>And for a site running on port 80</p>
<div class="example"><pre>
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
-RewriteRule ^/(.*) http://www.example.com/$1 [L,R]
+RewriteRule ^/?(.*) http://www.example.com/$1 [L,R]
</pre></div>
+
+ <p>
+ If you wanted to do this generically for all domain names - that
+ is, if you want to redirect <strong>example.com</strong> to
+ <strong>www.example.com</strong> for all possible values of
+ <strong>example.com</strong>, you could use the following
+ recipe:</p>
+
+<div class="example"><pre>
+RewriteCond %{HTTP_HOST} !^www\. [NC]
+RewriteCond %{HTTP_HOST} !^$
+RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R]
+</pre></div>
+
+ <p>These rulesets will work either in your main server configuration
+ file, or in a <code>.htaccess</code> file placed in the <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> of the server.</p>
</dd>
</dl>
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
-RewriteRule ^/(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R]
+RewriteRule ^/?(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R]
</pre></example>
<p>And for a site running on port 80</p>
<example><pre>
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
-RewriteRule ^/(.*) http://www.example.com/$1 [L,R]
+RewriteRule ^/?(.*) http://www.example.com/$1 [L,R]
</pre></example>
+
+ <p>
+ If you wanted to do this generically for all domain names - that
+ is, if you want to redirect <strong>example.com</strong> to
+ <strong>www.example.com</strong> for all possible values of
+ <strong>example.com</strong>, you could use the following
+ recipe:</p>
+
+<example><pre>
+RewriteCond %{HTTP_HOST} !^www\. [NC]
+RewriteCond %{HTTP_HOST} !^$
+RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R]
+</pre></example>
+
+ <p>These rulesets will work either in your main server configuration
+ file, or in a <code>.htaccess</code> file placed in the <directive
+ module="core">DocumentRoot</directive> of the server.</p>
</dd>
</dl>