I'm listening on an IP number that has a number of aliases:
www.domain.com
alias.domain.com
www.other.com
all point to the same address.
Now, I want alias.domain.com to 301 redirect to www.domain.com. We are
phasing out that name, and it's always been an alias to www.domain.com.
Note the rewrite below.
# Name-based virtual hosting
NameVirtualHost 123.456.678.123:80
<VirtualHost 123.456.678.123:80>
ServerName www.domain.com
Rewri*gine on
RewriteCond %{HTTP_HOST} alias.domain.com
RewriteRule ^/(.*) http://www.veryComputer.com/$1 [L,R=301]
[...]
</VirtualHost>
<VirtualHost 123.456.678.123:80>
ServerName www.other.com
[...]
</VirtualHost>
The reason this works is because someone with a HTTP_HOST of
alias.domain.com doesn't match either of my virtual hosts, so Apache
uses the first one. Sound correct?
My questions:
1) would it be better to add a separate virtual host section for that
name? If so, why?
<VirtualHost 123.456.678.123:80>
ServerName alias.domain.com
RewriteRule ^/(.*) http://www.veryComputer.com/$1 [L,R=301]
</VirtualHost>
2) Will placing the rewrite outside of all virtual hosts simply not
work? (Because Apache is processing the Virtual host before any
rewrites?)
Thanks,
--
pls note the one line sig, not counting this one.