Help with simple asp script

Discussion in 'OT Technology' started by mdaniel, May 17, 2004.

  1. mdaniel

    mdaniel S is for Shiksa

    Joined:
    May 6, 2000
    Messages:
    52,515
    Likes Received:
    316
    Location:
    Northwest Mejicooooooo
    First I'll say that I know little about web development, so bear with me. I have an account with 1and1.com. They say that if I need FrontPage extensions enabled for more than one domain in my account, then all domains must be pointed to the my root directory (/), which I have done. The root should only contain two files, default.asp and error.htm. The files for each domain should be in a separate folder under root and the default.asp file should redirect users to the appropriate location.

    So I have the following files and directories in my web space:

    /default.asp
    /error.htm
    /domain1/index.htm
    /domain2/index.htm

    users entering www.domain1.com should be redirected to www.domain1.com/domain1/index.htm

    users entering www.domain2.com should be redirected to www.domain2.com/domain2/index.htm

    I have tested the full URLs above and they work. But entering either www.domain1.com or www.domain2.com results in a 403:forbidden page.

    They gave me a sample script which I edited to fit my domain names. My default.asp is below:

    <%EnableSessionState=False
    host = Request.ServerVariables("HTTP_HOST")
    if host = "domain1.com" or host = "www.domain1.com" then
    response.redirect("http://www.domain1.com/domain1/index.htm")
    elseif host = "domain2.com" or host = "www.domain2.com" then
    response.redirect("http://www.domain2.com/domain2/index.htm")
    else

    'if we get no host or undefined host
    response.redirect("http://www.domain1.com/error.htm")
    end if
    %>

    Are asp files just plain text files like html files? I know that usually when you point a brower to a domain's root, the server automatically serves the index.htm or default.htm page. Is there something wrong with my script or is the server simply ignoring my default.asp page and giving the 403 because there is no index.htm. I can't find a setting where I specify which page I was the server to show by default.
     
  2. mdaniel

    mdaniel S is for Shiksa

    Joined:
    May 6, 2000
    Messages:
    52,515
    Likes Received:
    316
    Location:
    Northwest Mejicooooooo
    Doing more research, I found out how to edit the .htaccess file to tell the server to run default.asp when I point my browser to my domain. Now it just shows the text of the script instead of running it.
     
  3. Keyzs

    Keyzs OT Supporter

    Joined:
    Nov 3, 2003
    Messages:
    814
    Likes Received:
    0
    Location:
    Charlotte, MI
    What OS are you running on the server? In IIS's administration screen you can set 'Documents' where you would need to add Default.asp and probably more it to the top of the list.

    If this is a newly setup server and running W2k3 you need to Allow Active Server Pages in the Web Services Extension section of IIS.

    And for the code I would suggest:
    Code:
    <%
    Option Explicit
    EnableSessionState=False
     
    dim strHOST
    strHOST = ucase(Request.ServerVariables("HTTP_HOST"))
     
    if instr(strHOST,"DOMAIN1.COM") then 
         response.redirect("domain1/index.htm")
    elseif instr(strHOST,"DOMAIN2.COM") then 
         response.redirect("domain2/index.htm")
    else
         response.redirect("error.htm")
    end if
    %>
     
    Last edited: May 17, 2004
  4. mdaniel

    mdaniel S is for Shiksa

    Joined:
    May 6, 2000
    Messages:
    52,515
    Likes Received:
    316
    Location:
    Northwest Mejicooooooo
    Thanks. I did more research and it looks like my free account is hosted on a Linux machine so no asp support. Is there a way to do the same thing on a Linux box for a non-programmer like myself?
     
  5. carlin

    carlin Guest

    well first figure out which scripting languages are available to u.
     
  6. mdaniel

    mdaniel S is for Shiksa

    Joined:
    May 6, 2000
    Messages:
    52,515
    Likes Received:
    316
    Location:
    Northwest Mejicooooooo
    Thanks for the help but I figured it out. Turns out, 1and1 has both Linux and Windows hosted accounts. The instructions I read about pointing both domains to / and using a script to redirect only applies to Windows-hosted accounts. On the Linux accounts, which I now know I have, that entire procedure is unnecessary. Its actually far simpler under Linux with no redirection needed. :doh:
     
  7. Keyzs

    Keyzs OT Supporter

    Joined:
    Nov 3, 2003
    Messages:
    814
    Likes Received:
    0
    Location:
    Charlotte, MI
    Its simpler under Linux? Or you just were instructed on how to do it the right way? (To do what you wanted in IIS correctly is just a setting, just like Apache or most other web servers)

    The code is basically the same:
    ASP:
    <%
    if instr(strHOST,"DOMAIN1.COM") then
    response.redirect("domain1/index.htm")
    elseif instr(strHOST,"DOMAIN2.COM") then
    response.redirect("domain2/index.htm")
    else
    response.write("<center><b>You cannot access this site using that domain name</b></center>")
    end if
    %>


    PHP
    <?php
    if ($_SERVER['HTTP_HOST'] == 'DOMAIN1.COM') {
    header('Location: http://www.domain1.com/domain1/index.htm');
    }
    elseif ($_SERVER['HTTP_HOST'] == 'DOMAIN2.COM') {
    header('Location: http://www.domain1.com/domain2/index.htm');
    }
    else {
    // Either print error, or default page.
    }
    ?>
     
    Last edited: May 17, 2004
  8. mdaniel

    mdaniel S is for Shiksa

    Joined:
    May 6, 2000
    Messages:
    52,515
    Likes Received:
    316
    Location:
    Northwest Mejicooooooo
    I meant that on the Linux-hosted accounts, there was no need for a script to redirect users to the appropriate folder. Its handled in the control panel settings. At least its easier for me as a non-coder to handle since its just control panel point and click to ensure each domain's requests make it to the proper folder.
     

Share This Page