mod_rewrite and name-based virtual hosts

mod_rewrite and name-based virtual hosts

Post by Bill Mosele » Mon, 03 Jan 2000 04:00:00



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.

 
 
 

mod_rewrite and name-based virtual hosts

Post by Mark Mentova » Mon, 03 Jan 2000 04:00:00



>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.

Rather than use mod_rewrite, why not use the Redirect directive?  Rather
than this:

Quote:><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>

Try this:

<VirtualHost 123.45.67.89:80>
  ServerName alias.domain.com
  Redirect / http://www.veryComputer.com/
</VirtualHost>

It's more simple and to the point that fiddling with mod_rewrite, and it
was designed for exactly the application you have in mind.

Mark

 
 
 

mod_rewrite and name-based virtual hosts

Post by Bill Mosele » Mon, 03 Jan 2000 04:00:00



remarked...

Quote:> Try this:

> <VirtualHost 123.45.67.89:80>
>   ServerName alias.domain.com
>   Redirect / http://www.domain.com/
> </VirtualHost>

> It's more simple and to the point that fiddling with mod_rewrite, and it
> was designed for exactly the application you have in mind.

Oh, thanks.  I was thinking Redirect only matched explicit URL paths.  
Thanks for the reminder.

--

pls note the one line sig, not counting this one.

 
 
 

1. Mixing Apache Name Based Virtual Hosts and SSL Virtual Host

This query refers to Apache 1.3.24 and mod_ssl 2.8.8-1.3.24, on
Solaris 8.

I am running a bunch of name-based virtual hosts on port 80 using a
wildcard in the NameVirtualHosts directive. I am load balancing across
a lot of real servers and want to have the same config files on each
server, so I don't want to have to specify the server IP address in
httpd.conf.

I now want to add an SSL virtual host on port 443. I know that I can't
have name-based virtual hosts with SSL, and I don't need them -- I
just need the one. But if I try to add a virtual host configuration
like:

<VirtualHost _default_:443>
    [SSL configuration stuff]
</VirtualHost>

I get the error message "mixing * ports and non-* ports with a
NameVirtualHost address is not supported, proceeding with undefined
results".

Is there any other way I can have several name-based virtual hosts on
port 80, a single SSL virtual host on port 443 and not have to put the
server IP address in httpd.conf?

2. Perl Calling C Issue??

3. Name-based vs IP based virtual hosts

4. Linux serial speed inadequate?

5. Mixing IP-based and name-based virtual hosts?

6. *.20pre8-ac2 compile fails on SPARC

7. Can IP-based and Name-Based Virtual Hosting coexist

8. Sol10(x86) pkg-get prob

9. Setting up IP-based and Name-based virtual hosting side by side...

10. Help: setup name-based or port-based virtual web host.

11. Appropriate HTTP Error Code for "No Default Host" in Name-Based Virtual Host Setup

12. Name Based Virtual Hosting - Unable to access Virtual domain from IE/Lynx

13. name based vi IP based virtual hosts