Redirect a Subdomain to Point to a Subdirctory

Discussion in 'Domain names / DNS' started by cachevalley, Sep 9, 2011.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I know there is answer to this in the KB, however I'm still not understanding how exactly I am supposed to do this.

    My subdomain is www.cachevalleyparadeofhomes.com and I would like to point it to www.cvhba.com/parade_of_homes.html. The help in the KB says to place the following code in a default document on the document root. I am new to this and don't totally understand what all of this means so my questions are below.

    <%
    If InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("subdomain1.YourHostedDomainName.com") ) > 0 Then
    Response.Redirect("/subdomain1")
    ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("subdomain2.YourHostedDomainName.com") ) > 0 Then
    Response.Redirect("/subdomain2")
    ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("subdomain3.YourHostedDomainName.com") ) > 0 Then
    Response.Redirect("/subdomain3/home.asp")
    End If
    %>

    1. Do I just make a new default.html document or add it to my index.html? If adding it to index.html, where do I add it to the code?
    2. What do I put in as the SERVER_NAME?
    3. What do I put for the subdomain1.YourHostedDomainName.com for sure? Is it www.cachevalleyparadeofhomes.cvhba.com?
    4. Does /subdomain1 = /www.cvhba.com/parade_of_homes.html?
    5. What do I put for all the other subdomain#'s?

    Again, I apologize for all of the questions, but I appreciate any help I can get.

    Thanks,
    Melissa
     
  2. <%
    If InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("cachevalleyparadeofhomes.cvhba.com") ) > 0 Then
    Response.Redirect("/parade_of_homes.html")
    End If
    %>

    Copy and paste it to your notepad, save as ASCII text with .aspx extension name it as default.aspx (see the default document tab in IIS tool within the control panel. The first line in the box is your default document)
     
  3. The rest of redirect

    Hi!

    I was setting up my sub domains as well.

    Here is my script in a file called redirect.asp

    HTML:
    <%@ Language="VBScript" %>
    
    <%
    If InStr( UCase(Request.ServerVariables("SERVER_NAME")),  UCase("blog.nostrotech.com") ) > 0 Then
            Response.Redirect("/blog/")
    ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("project.nostrotech.com") ) > 0 Then
            Response.Redirect("/project/")
    ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("projects.nostrotech.com") ) > 0 Then
            Response.Redirect("/project/")
    ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("cms.nostrotech.com") ) > 0 Then
            Response.Redirect("/cms/")
    Else
            Response.Redirect("/")
    End If
    %>
    Now, the last Else part is for default case if no other subdmain was specified. I don't want to die within this file. Thing is, my main website is a MVC 4. The above script works fine: the sub domains are redirected and the main site is also working. The issue is that, if a user does give an unknown subdir or sub domain, I'd want to catch that error in mt MVC site and redirect to a proper error page. How do I do that? I also want this scrip to be a part of my MVC 4 site's default page. Any ideas?
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page