Commit 9b6efd10 authored by Richard Bowen's avatar Richard Bowen
Browse files

This adds a more generic "add www. to all hostnames" ruleset.

It also makes the existing rulesets in this section work both in the
main configuration file and in .htaccess files, by making the leading
slash optional - ie ^/?


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@685411 13f79535-47bb-0310-9956-ffa450edef68
parent 87285d44
Loading
Loading
Loading
Loading
+18 −2
Changes for docs/manual/rewrite/rewrite_guide.html.en: 18 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -120,15 +120,31 @@ RewriteRule ^/u/(<strong>[^/]+</strong>)$ /$1/$2<strong>/</strong> [<strong
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>

+19 −2
Changes for docs/manual/rewrite/rewrite_guide.xml: 19 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -109,15 +109,32 @@ RewriteRule ^/u/(<strong>[^/]+</strong>)$ /$1/$2<strong>/</strong> [<strong
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>