[H-GEN] Multiple Domains - Apache
Nikolai Lusan
nikolai at lusan.id.au
Mon Apr 28 21:31:03 EDT 2008
hey,
This is a bad way of doing this. There are a number of ways to do this,
the easiest is to have a file that the main config can import to handle
these, it might get out of control if you start hosting large numbers of
<site>.domain[a-b].com on the same server ... remember not everything
needs to be done in a <VirtualHost> directive, only things specific to
that <VirtualHost>. Also look at
http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html#canonicalhost
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domaina\.com$ [NC]
RewriteCond %{HTTP_HOST} !^exception\.domaina\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domaina\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^domaina\.com$ [NC]
RewriteRule ^/(.*) http://www.domaina.com/$1 [L,R=permanent]
RewriteCond %{HTTP_HOST} !^www\.domainb\.com$ [NC]
RewriteCond %{HTTP_HOST} !^exception\.domainb\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domainb\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^domainb\.com$ [NC]
RewriteRule ^/(.*) http://www.domainb.com/$1 [L,R=permanent]
You may also want [QSA], but I don't know what you have coming into your
ruleset. These will match anything under either domain that isn't the
www site or any exceptions listed and redirect it. Take it from someone
who has had to admin large numbers of <VirtualHosts> with similar
redirects and rewrites, using includes makes it easier, and if you are
brave enough using environment vars makes it easier (word to the wise
standard apache SetEnv's are available in rewrite and [PT] may be your
friend)
On Tue, 2008-04-29 at 05:10 +0530, Deepan wrote:
> NameVirtualHost *:80
>
> <VirtualHost *:80>
> DocumentRoot /var/www/html/domaina/
> ServerName www.domaina.com
> Options +FollowSymLinks
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^domaina\.com$ [NC]
> RewriteRule ^(.*)$ http://www.domaina.com$1
> [R=301,L]
> </VirtualHost>
>
>
> <VirtualHost *:80>
> DocumentRoot /var/www/html/domainb/
> ServerName www.domainb.com
> Options +FollowSymLinks
> RewriteEngine On
> RewriteCond %{HTTP_HOST} ^domainb\.com$ [NC]
> RewriteRule ^(.*)$ http://www.domainb.com$1
> [R=301,L]
> </VirtualHost>
--
Nikolai Lusan
More information about the General
mailing list