]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
This adds a more generic "add www. to all hostnames" ruleset.
authorRich Bowen <rbowen@apache.org>
Wed, 13 Aug 2008 01:29:03 +0000 (01:29 +0000)
committerRich Bowen <rbowen@apache.org>
Wed, 13 Aug 2008 01:29:03 +0000 (01:29 +0000)
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

docs/manual/rewrite/rewrite_guide.html.en
docs/manual/rewrite/rewrite_guide.xml

index ae36b5352ae7f22d999cc6cfc27173280fcb3b5c..705eeb8aa5e2ad2052d2633d157a888989a086d0 100644 (file)
@@ -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>
 
index 898a99cb586168290c5948f576252aa6ec09f3a7..ff21d5f6fbb11498b29e61590a6ec1903b2d6677 100644 (file)
@@ -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>