开发者

how to achieve xxx.domainname.com URL pattern?

开发者 https://www.devze.com 2022-12-27 03:49 出处:网络
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开发者_如何学

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..


  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.


  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
    
0

精彩评论

暂无评论...
验证码 换一张
取 消