1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

Virtual Subdomain

Discussion in 'Plesk for Windows - 8.x and Older' started by Glen, Jan 21, 2008.

  1. Glen

    Glen Guest

    0
     
    How do I create a situation that any subdomain redirects to the main domain? We already have a wildcard in our DNS but anything.mysite.com displays the default plesk page instead of www.mysite.com. I'm looking for a solution that isn't destroyed if I change something else with plesk and that works for all domains that I host without having to have a separate IP address for every domain.
     
  2. shall

    shall Regular Pleskian

    26
    57%
    Joined:
    Apr 2, 2007
    Messages:
    226
    Likes Received:
    0
    Hi Glen,

    Directly within IIS you can create a 'default' site (one that responds whenever a site is not aliased to it) to run on all ip addresses. Then create a default.asp file in the folder which you've mapped that site to which reads something like this (you might have to play with it):

    <%

    '[Settings]
    sQD = Replace(Request.ServerVariables("SERVER_NAME"), "'", "''")
    sQD = Replace(sQD, "\", "\\")

    ' get just the FQDN from the server name
    Dim rv
    Set rv = New RegExp
    rv.Global = True
    rv.MultiLine = True
    rv.IgnoreCase = True
    rv.Pattern = "([a-zA-Z0-9\-\_]*\.[a-zA-Z]*)$"
    If rv.Test(sQD) Then sQD = rv.Execute(sQD)(0).Value
    Set rv = Nothing

    ' redirect
    Response.Redirect "http://" & sQD & "/"
    %>
     
  3. Glen

    Glen Guest

    0
     
    Hi Shal,

    Tnx. In your solution, what is displayed in the address bar? Is it 'anything.mysite.com' or 'www.mysite.com'?

    Reading back my own post, I think I have not been so clear (sorry for that). What I want is the address bar to display the subdomain and arrange what is displayed in the browser using ISAPI-rewrite. So 'anything.mysite.com' is in the address bar but the browser displays 'www.mysite.com/?user=anything'. The problem with ISAPI-rewrite seems to be that it doesn't catch the requests because the subdomains land on the 'default site'.

    With what you describe, I think I don't need ISAPI-rewrite at all because I could tune the redirect script to create the url 'www.mysite.com/?user=anything'. But it all depends on whether the original subdomain stays in the address bar or not.
     
  4. shall

    shall Regular Pleskian

    26
    57%
    Joined:
    Apr 2, 2007
    Messages:
    226
    Likes Received:
    0
    Well, that's different...

    Hi Glen,

    Ah, so you need to preserve the extra text from the subdomain. What you preserve in the address bar could be a few different things. You could have it create a frameset or redirect to the querystring URL. The code above doesn't do that, it just redirects to the root page. You're probably looking for something closer to this:

    Code:
    <%
    
    '[Settings]
      bDisplay = 1 ' use 1 for frameset, 0 for redirect
      sTag = ""    ' default tag
    
    '[Parse]
      sQD = Replace(Request.ServerVariables("SERVER_NAME"), "'", "''")
      sQD = Replace(sQD, "\", "\\")
    
    ' get just the FQDN from the server name
      Dim rv
      Set rv = New RegExp
      rv.Global = True
      rv.MultiLine = True
      rv.IgnoreCase = True
      rv.Pattern = "([a-zA-Z0-9\-\_]*\.[a-zA-Z]*)$"
      If rv.Test(sQD) Then
        sDom = rv.Execute(sQD)(0).Value
        sTag = Replace(sQD, sDom, "")
      End If
      Set rv = Nothing
    
    '[Redirect]
      sUrl = "http://" & sDom & "/?user=" & sTag
      If bDisplay = 0 Then
      ' straight redirect
      ' replaces "joe.example.com" with "example.com/?user=joe"
        Response.Redirect sUrl
      Else
      ' frame
      ' preserves "joe.example.com" within address bar
        Response.Write "<html>" & vbCrLf
        Response.Write "<frameset cols=""100%"">" & vbCrLf
        Response.Write "  <frame src=""" & sUrl & """ />" & vbCrLf
        Response.Write "</frameset>" & vbCrLf
        Response.Write "</html>"
      End If
    
    %>
    
    That'll do what you're after. Change the "bDisplay" value to toggle how it works. Right now (1) it's setup to frame the new page so the original URL is preserved in the address bar.
     
Loading...