From: Rich Bowen Date: Wed, 13 Aug 2008 01:29:03 +0000 (+0000) Subject: This adds a more generic "add www. to all hostnames" ruleset. X-Git-Tag: 2.3.0~370 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=600d513c5cc8cb3aa5e4924cc2b262036227a2b5;p=thirdparty%2Fapache%2Fhttpd.git 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 --- diff --git a/docs/manual/rewrite/rewrite_guide.html.en b/docs/manual/rewrite/rewrite_guide.html.en index ae36b5352ae..705eeb8aa5e 100644 --- a/docs/manual/rewrite/rewrite_guide.html.en +++ b/docs/manual/rewrite/rewrite_guide.html.en @@ -120,15 +120,31 @@ RewriteRule ^/u/([^/]+)$ /$1/$2/ [

And for a site running on port 80

 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]
 
+ +

+ If you wanted to do this generically for all domain names - that + is, if you want to redirect example.com to + www.example.com for all possible values of + example.com, you could use the following + recipe:

+ +
+RewriteCond %{HTTP_HOST} !^www\. [NC]
+RewriteCond %{HTTP_HOST} !^$
+RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R]
+
+ +

These rulesets will work either in your main server configuration + file, or in a .htaccess file placed in the DocumentRoot of the server.

diff --git a/docs/manual/rewrite/rewrite_guide.xml b/docs/manual/rewrite/rewrite_guide.xml index 898a99cb586..ff21d5f6fbb 100644 --- a/docs/manual/rewrite/rewrite_guide.xml +++ b/docs/manual/rewrite/rewrite_guide.xml @@ -109,15 +109,32 @@ RewriteRule ^/u/([^/]+)$ /$1/$2/ [

And for a site running on port 80

 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]
 
+ +

+ If you wanted to do this generically for all domain names - that + is, if you want to redirect example.com to + www.example.com for all possible values of + example.com, you could use the following + recipe:

+ +
+RewriteCond %{HTTP_HOST} !^www\. [NC]
+RewriteCond %{HTTP_HOST} !^$
+RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R]
+
+ +

These rulesets will work either in your main server configuration + file, or in a .htaccess file placed in the DocumentRoot of the server.