File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Wild Card Sub Domains Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Wild Card Sub Domains" Watch "Wild Card Sub Domains" New topic

Wild Card Sub Domains

Louis Bros
Ranch Hand

Joined: Jun 03, 2011
Posts: 54

Hi all,

I'm trying to set up a wildcard sub domain where

* maps to

Currently my server.xml looks like this

I've seen an example of what I want to do where

Is placed within the sub domain host element. I've read however that, that can cause problems and that context elements should be kept out of the server.xml and instead be defined in the context.xml.

Right now both the sub domain and the domain will map to the ROOT folder. So at this stage I think I could use a filter to forward according to the sub domain or I could do something to the context.xml.

Could someone please suggest the correct way of implementing this and if I need to use the context.xml what should the context element look like?

Thanks, Louis

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

You're talking about 2 different animals here.

Actually, "*" wouldn't represent wildcard sub-domains, it would represent wildcard hostnames. A fully-qualified domain name (FQDN) includes the hostname as its first element. A true wildcard subdomain name would be "*.*" or "www.*". The domain name can never be a wildcard.

In order to implement such a scheme, however, you'd need a specialized Domain Name Server setup for your authoritative name servers. DNS is basically supposed to be a "telephone directory" where, given a FQDN, the directory is consulted, and (assuming a match), a corresponding IP address is returned. What you'd need would be a DNS server that - instead of serving as a database - cooked up IP addresses on the fly. Which wouldn't be that hard if you only have one server, but I happen to have more than physical host on my domain, so the logic would be more complicated than just "match anything/return same thing" in my case.

You also probably won't make many friends using this scheme, since for performance reasons, DNS entried are usually cached at various levels between client and server, and caching and dynamic DNS are somewhat opposed.

The second part of your question can be resolved in several ways. One way is to front Tomcat with a server that can translate URLs such as Apache. Another way is to deploy your webapp at the context root for the Tomcat Host.

An IDE is no substitute for an Intelligent Developer.
Louis Bros
Ranch Hand

Joined: Jun 03, 2011
Posts: 54

Thanks very much for the explanation, I better read up
I agree. Here's the link:
subject: Wild Card Sub Domains
It's not a secret anymore!