Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post

    Sub-domain redirecting

    Hello,

    I have an account at brinkster.com for my website, http://www.rallystuff.net. As I have a separate website within a folder on my site (http://www.rallystuff.net/lomax/index.aspx) I want use a subdomain called http://mosasaur.rallystuff.net to access this site. However when brinkster created me this subdomain it takes you to the homepage of my main site. They have told me that to redirect this link to /lomax I have to use the code below. However because my knowledge of PHP is very limited as I code in ASP.NET, and I haven't got contact with the guy who originally designed my site I don't know how to edit this code to make it work.

    Any help would be most appreciated,
    Thanks,
    Curt.

    Code:
    <?
    $SiteNameURL = $_SERVER['HTTP_HOST'];
    
    switch ($SiteNameURL) {
    
    case "domain.com":
    include 'page1.php';
    break;
    
    case "www.domain.com":
    include 'page1.php';
    break;
    
    case "yourotherdomain.com":
    include 'page2.php';
    break;
    
    case "www.yourotherdomain.com":
    include 'page2.php';
    break;
    
    case "subdomain1.domain.com":
    include 'page3.php';
    break;
    
    case "subdomain2.domain.com":
    include 'page4.php';
    break;
    
    default:
    include 'other.php';
    
    }
    ?>

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That code is including file. If you want to redirect use header("Location...
    http://uk.php.net/header


    PHP Code:
    case "subdomain1.domain.com":
    header("Location: http://www.rallystuff.net/lomax/index.aspx");
    break; 

  • #3
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Thanks for your help. I tried this but it still wouldn't work. This is the code I used:

    Code:
    <?
    $SiteNameURL = $_SERVER['HTTP_HOST'];
    
    switch ($SiteNameURL) {
    
    case "mosasaur.rallystuff.net":
    header("Location: http://www.rallystuff.net/lomax/index.aspx"); 
    break;
    
    }
    ?>
    I get this error:

    "Warning: Cannot modify header information - headers already sent by (output started at c:\Sites\Single18\curttimson\webroot\index.php:9) in c:\Sites\Single18\curttimson\webroot\index.php on line 15"


    Any ideas whats wrong?
    Thanks,
    Curt.

  • #4
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Could it be anything to do with where it is put in the code. If so this is the code above the HTML tag:

    Code:
    <?php
    
    include("connect.inc");
    
    include('news.inc');
    
    ?>
    
    <?
    $SiteNameURL = $_SERVER['HTTP_HOST'];
    
    switch ($SiteNameURL) {
    
    case "mosasaur.rallystuff.net":
    header("Location: http://www.rallystuff.net/lomax/index.aspx"); 
    break;
    
    }
    ?>

  • #5
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Ive worked out where I went wrong. It has to be in the <?php tag:

    Code:
    <?php
    
    include("connect.inc");
    
    include('news.inc');
    
    
    
    $SiteNameURL = $_SERVER['HTTP_HOST'];
    
    switch ($SiteNameURL) {
    
    case "mosasaur.rallystuff.net":
    header("Location: http://www.rallystuff.net/lomax/index.aspx");
    break;
    
    }
    
    ?>
    Thanks for your help.

  • #6
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    put the "header" before any echo in the php script and before the very first html part( before <html>)

  • #7
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by coyotte508
    put the "header" before any echo in the php script and before the very first html part( before <html>)
    The way I have it above works fine thanks. However when mosasaur.rallystuff.net redirects to /lomax the URL appears as /lomax. Is there a way of having it appear as mosasaur.rallystuff.net instead?

  • #8
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's the way you have it setup.

    If you want it to be on the URL then you will have to create it into a proper sub domain rather than a redirect. You do this at server level.

    The other option is to use a frame redirect. Not pretty.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •