httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JBT <jul...@gmail.com>
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 <warp-9.9@usa.net> wrote:

> > Having virtual default host listening to domain.net and
> > dns for http://*.domain.net rewrites to http://domain.net
> > 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: anything.domain.net. 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 domain.net suffix, then go to
> domain.net

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

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

One can see this example in action on: http://jult.net
Try http://anythingyoulike.jult.net 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:

domain.com -> domain.com
www.domain.com -> the.domain.com

and it worked:

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

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 : mail.domain.net -> V4
> V4 : HTTPS : mail.domain.net -> (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.
-- 
Adios

Julius

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message