httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JBT <>
Subject Re: [users@httpd] Redirect HOSTname to https virtual host
Date Tue, 11 Jan 2005 13:06:52 GMT
On Tue, 11 Jan 2005 02:44:19 -0500, Leif W <> wrote:

> > Having virtual default host listening to and
> > dns for http://* rewrites to
> > this goes to one port 80 document root, all fine and dandy.
> I don't know of a way to set up sub-domain defaults to literally catch
> anything a user might type in: I know how to set
> up the DNS with the wildcard, but I have no idea how to set up Apache to
> match the trailing part of the Host header, and if the prefix doesn't
> match a valid host with the same suffix, then go to

I did some toying with that 4 years ago, and came up with this hack;
(example, it works wonders ;-)

<VirtualHost *:80>
DocumentRoot /var/www/domain
ServerAlias *
RewriteEngine on
RewriteCond %{HTTP_HOST}                !^$
RewriteRule ^/(.*)            $1 [L,R]
RewriteOptions inherit

One can see this example in action on:
Try and it does what you want it to ;-)

Another fun example is the rewrite where you
want a hostname to appear, but *only if* one is put in.
I had a client once who asked me if this was possible,
where they wanted the shorter name to remain,
and the "www" to change into something funny. So: -> ->

and it worked:

<VirtualHost *:80>
DocumentRoot /var/www/domain
ServerAlias *
RewriteEngine on
RewriteCond %{HTTP_HOST}                !^$
RewriteCond %{HTTP_HOST}                !^$
RewriteRule ^/(.*)            $1 [L,R]
RewriteOptions inherit

Both of the above examples are in Apache 2 config style,
don't recall if it was the same in older versions, I think it was.

> V3 : HTTP : -> V4
> V4 : HTTPS : -> (self)

> V3: You have one or more VHOST configs which redirect from HTTP to HTTPS
>    (target host name irrelevant, only unique IP:PORT pair matters).
> V4: You have one or more VHOST configs each with a unique IP:PORT pair
>    and certificate with common name matching ServerName, which serves
>    encrypted content using SSL or TLS.

I tried this, but somehow the hostname mail for the default domain
would not listen to its name within a separate Vhost container.
Not sure why yet, I might be overlooking something elsewhere.
The wildcarded * DNS for the hostname has no influence on this,
it just picks up where there aren't any hostnames configged,
Apache takes over where the hostname comes in
and as long as its valid, it will cause no problems.


The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message