From: Rich Bowen
Date: Fri, 11 Dec 2015 21:51:49 +0000 (+0000)
Subject: Handle www.example.com separately from foo.example.com, as per request
X-Git-Tag: 2.5.0-alpha~2540
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bd0188b6c77b4cee6fb82b94e084a85ed65a9a3;p=thirdparty%2Fapache%2Fhttpd.git
Handle www.example.com separately from foo.example.com, as per request
on IRC.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1719574 13f79535-47bb-0310-9956-ffa450edef68
---
diff --git a/docs/manual/rewrite/vhosts.xml b/docs/manual/rewrite/vhosts.xml
index 757cc83aa1d..26b447eb406 100644
--- a/docs/manual/rewrite/vhosts.xml
+++ b/docs/manual/rewrite/vhosts.xml
@@ -32,7 +32,7 @@
how you can use mod_rewrite to create dynamically
configured virtual hosts.
-mod_rewrite is not the best way to configure
+mod_rewrite is usually not the best way to configure
virtual hosts. You should first consider the alternatives before resorting to
mod_rewrite. See also the "how to avoid
@@ -62,9 +62,10 @@ mod_rewrite document.
new VirtualHost sections.
In this recipe, we assume that we'll be using the hostname
- www.SITE.example.com for each
+ SITE.example.com for each
user, and serve their content out of
- /home/SITE/www.
+ /home/SITE/www. However, we want
+ www.example.com to be ommitted from this mapping.
Solution:
@@ -74,10 +75,11 @@ mod_rewrite document.
RewriteEngine on
-RewriteMap lowercase "int:tolower"
+RewriteMap lowercase int:tolower
-RewriteCond "${lowercase:%{HTTP_HOST}}" "^www\.([^.]+)\.example\.com$"
-RewriteRule "^(.*)" "/home/%1/www$1"
+RewriteCond %{HTTP_HOST} !^www\.
+RewriteCond ${lowercase:%{HTTP_HOST}} ^([^.]+)\.example\.com$
+RewriteRule ^(.*) /home/%1/www$1
Discussion
@@ -100,6 +102,10 @@ used in RewriteRule are
captured into the backreferences $1, $2,
etc.
+The first RewriteCond checks to see if the hostname
+starts with www., and if it does, the rewriting is
+skipped.
+
As with many techniques discussed in this document, mod_rewrite really
isn't the best way to accomplish this task. You should, instead,