Subdomain and Domain maping to subfolders

Discussion in 'Site Programming, Development and Design' started by Nikola Tesla, Sep 30, 2009.

  1. Make a root.aspx and put it in the root of your site. In IIS 7 manager make it to be on top of the list in Default Documents. Put this code in code behind file in PageLoad method:
    Code:
     string strServerName = Request.ServerVariables["SERVER_NAME"].ToString();
    
                if (strServerName == "subdomain.domain.com")
                {
                    Response.Redirect("http://www.domain.com/subdomainfolder/example.aspx", true);
                }
                else if (strServerName == "anotherdomain.com")
                {
                    // ... you know the rest
                    // ...
    
    Subdomain redirection is working for "http://subdomain..." but now does not work with "www.subdomain..."

    Feel free to make suggestions.

    ----------
    givlupieomjpdy
     
  2. Ray

    Ray

    Did you define the subdomain within your Site Info Manager? Under the Site Info Manager/Subdomain you still will need to define www.subdomain.domain.com as well as defining subdomain.domain.com.
     
  3. Yes. But ...

    ... I already added www.subdomain.domain.com and subdomain.domain.com to the ...

    https://cp.Winhost.com/domains/dns.aspx
    https://cp.Winhost.com/sites/subdomain.aspx

    Do I need to wait for TTL timers to refresh DNS records?

    ------------------
    | givlupieomjpdy |
     
    Last edited by a moderator: Oct 14, 2015
  4. So this is updated code for root redirect:
    Code:
    string strServerName = Request.ServerVariables["SERVER_NAME"].ToString();
    
    if (strServerName == "subdomain.domain.com" || strServerName == "www.subdomain.domain.com")
    {
    Response.Redirect("http://www.domain.com/subdomainfolder/example.aspx", true);
    }
    else if (strServerName == "anotherdomain.com" || strServerName == "www.anotherdomain.com")
    {
                    // ... you know the rest
                    // ...
    
    "Subdomains and Domains mapping (redirect) to subfolders" done.
     
  5. Ray

    Ray

    Nice job. Your method sure makes the nested conditional statement much cleaner and easier to read.
     
  6. I have attempted this using URL rewrite (although not sure if it will work as my NS servers are not up to date); this is what I have come up with.

    The URLs currently look as follows (migrating hosts): http://jonathan.dickinsons.co.za/blog/...

    1. Create a subfolder for your subdomain, (not application).
    2. Add a new rewrite rule to it.
    3. Precondition: .* (Regex)
    4. Condition: {URL} matches the pattern .*://jonathan\.dickinsons\.co\.za(.*)? (Regex)
    5. Rewrite to: jonathan/{C:1}
    6. Append query string: don't.

    Any further ideas/corrections?
     
  7. Ray

    Ray

    First you should make sure that jonathan.dickinsons.co.za resolves to the Winhost web server. If you ping jonathan.dickinsons.co.za you will see that it is not even resolving to Winhost. At this point the URL Rewrite/Redirect rule will not even work since jonathan.dickinsons.co.za is not pointing to Winhost.
     
    Last edited by a moderator: Oct 14, 2015
  8. :) - as I said that's the theory. I have to wait for the NS servers to transfer from my old host before I can test anything out.
     
  9. Ray

    Ray

    Then try to set the A record for jonathan.dickinsons.co.za to point to IP address 96.31.35.44. Otherwise we really can't test if the URL Rewrite rule is working correctly.
     

Share This Page