I have created an application which needs to accept wildcard dns and request to database using that wildcard value. I tried to simulate a virtual environment for myself to achieve what I want like this:
1) in my Linux OS I changed the /etc/hosts and add these lines :
127.0.0.1 test-domain.com 127.0.0.1 mehdi.test-domain.com
2) I changed my tomcat server.xml file as follows :
<Host name="test-domain.com" appBase="webapps/ROOT" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>www.test-domain.com</Alias> <Context path="" docBase="."/> </Host> <Host name="*.test-domain.com" appBase="webapps/ROOT" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>*.test-domain.com</Alias> <Context path="" docBase="."/> </Host>
3) I deploy my project war file 'Root.war' into the ${TOMCAT}/webapps/ROOT folder
now when I request "www.test-domain.com" I see the web home page, and I want when I type this url "mehdi.test-domain.com", I fetch mehdi from the URL and do something with it and show mehdi page to my users.
Question 1: How I can fetch the wildcard value in my application ?
Question 2: Is it possible that we let tomcat convert the request URL to something else at runtime like this and pass it to the application (I need the wildcard value ex: mehdi)?
http://mehdi.test-domain.com CONVERT TO http://test-domain.com/mehdi
Question 3: Is it possible to have only the second < Host name=... definition and remove the first one? how could I handle it inside my application ?