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 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation PHP redirect script PLZ HELP ME

    Hello, i've recently bought a hosting package that allows me to point unlimited domains to my site. I would like different pages to display for each domain, but I get the same site.

    Could anyone PLEASE design a script that will detect what domain is in the address bar and redirect to the corresponding folder

    thx

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    If the hosting has cPanel included there is a redirects section that allows you to do this easily.

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think you can detect this through $_SERVER['SERVER_NAME'] or $_SERVER['HTTP_HOST']

  • #4
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SeeIT Solutions
    If the hosting has cPanel included there is a redirects section that allows you to do this easily.


    it doesnt unfortunately



    thx 4 ur help anyway

  • #5
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by delinear
    I think you can detect this through $_SERVER['SERVER_NAME'] or $_SERVER['HTTP_HOST']

    thx, but i'm not very good with php

    PHP Code:
    if ($_SERVER['HTTP_HOST'] == "www.mydomain.com")
    {
    //then what
    }


    // i suppose ill have lots of elses underneath for al my domains 
    3 Questions

    1.)Could somebody do it for me? please
    2.)If not, is that right?
    3.)How do I do the redirect bit?

  • #6
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you just want to do a very simple redirect from index.php in the root to an index file in a sub directory (which I think will be the best option if you're still learning php) then you could do something like this:

    PHP Code:
    if(strpos($_SERVER['HTTP_HOST'], 'domain1.com')) {

        
    header('Location: directory1/index.php');

    } elseif(
    strpos($_SERVER['HTTP_HOST'], 'domain2.com')) {

        
    header('Location: directory2/index.php');
        

    Although I'm sure there is a better solution using Apache to determine the domain and automatically show the correct sub directory, but I wouldn't know enough about Apache to be much help there.

  • #7
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thx


    um.........will that work when there is www. or http:// in front?

  • #8
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It should do, strpos() will determine if the domain appears anywhere within the $_SERVER['HTTP_HOST'] variable, so by leaving off the http and www parts you will catch anyone who arrives at the page without typing those parts too (hopefully!).

  • #9
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by delinear
    It should do, strpos() will determine if the domain appears anywhere within the $_SERVER['HTTP_HOST'] variable, so by leaving off the http and www parts you will catch anyone who arrives at the page without typing those parts too (hopefully!).
    i havent had any probs yet


    thx again


  •  

    Posting Permissions

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