From 600d513c5cc8cb3aa5e4924cc2b262036227a2b5 Mon Sep 17 00:00:00 2001 From: Rich Bowen Date: Wed, 13 Aug 2008 01:29:03 +0000 Subject: [PATCH] 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 --- docs/manual/rewrite/rewrite_guide.html.en | 20 ++++++++++++++++++-- docs/manual/rewrite/rewrite_guide.xml | 21 +++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/docs/manual/rewrite/rewrite_guide.html.en b/docs/manual/rewrite/rewrite_guide.html.en index ae36b5352a..705eeb8aa5 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 898a99cb58..ff21d5f6fb 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.

-- 2.40.0