how to achieve xxx.domainname.com URL pattern?

2019-07-27 16:16发布

Consider the case of blogspot.com the domain is the one blogspot.com only but suppose i register in it with xxx then i will have xxx.blogspot.com like wise here it won't be the subdomain (i can smell) , but its some thing different ... how to achieve this ?? in j2ee web application..

2条回答
孤傲高冷的网名
2楼-- · 2019-07-27 16:27
  1. Buy a domain name at you're favorite ISP.

  2. Configure for this domain a domain wildcard for the A record in the DNS zonefile (usualy using some nice tool from you're ISP):

    *   IN  A   74.125.77.191
    
  3. Code a Java Servlet (or whatever you are using) as front controller. The front controller will dispatch you to what ever the subdomain needs to show.

    String domain = request.getLocalName();
    String subdomain = domain.substring(0, domain.indexOf('.'));
    goto(subdomain); // or what ever you need for the subdomain
    
查看更多
SAY GOODBYE
3楼-- · 2019-07-27 16:34
  1. you need a DNS server that will resolve any subdomain as the adress of your server,
  2. you j2ee application can optain the hostname from the request header

UPDATE: here is a example of a BIND zone file:

$ttl 38400
mauriceperry.ch.    IN  SOA ks31441.kimsufi.com. maurice.mauriceperry.org. (
            1237374933
            10800
            3600
            604800
            38400 )
mauriceperry.ch.    IN  NS  ks31441.kimsufi.com.
mauriceperry.ch.    IN  NS  ns.kimsufi.com.
*   IN  A   213.186.61.21

Here xxx.mauriceperry.ch will resolve to 213.186.61.21 whatever xxx is.

查看更多
登录 后发表回答