How can I detect a subdomain in the url, and then run a servlet in a subfolder based on that subdomain. For example: if I had a domain example.com which had a registered subdomain blog.example.com (but that doesn’t point to a different server) and the user types the url blog.example.com into the adress bar, how would I start the servlet example.com/BlogServlet/ExamplePath, and send the relevant data to the user, without having to change/redirect the url to the servlet?
Thanks very much.
You are going to have to re-write the URL. That opens up all sorts of potential problems with cookie paths, location headers for redirects, links embedded in pages etc. There are ways of solving each of those issues if you are affected.
To get back to how to do it. In a servlet container, I’d use http://www.tuckey.org/urlrewrite/. In a reverse proxy, I’d use httpd mod_rewritealong with mod_headers and mod_substitute to fix the problems. Alternatively, mod_proxy could be used in place of mod_rewrite.