SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict phptek's Avatar
    Join Date
    Jun 2002
    Location
    Wellington, NZ
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detect HTTP URL using PHP

    G'day folks -

    I have 2 domains pointing to the same root directory:
    http://www.domain1.com and http://www.domain2.com

    I'd like to be able to use PHP to detect which URL is incoming and redirect all traffic from http://www.domain2.com to a sub domain of: http://subdmain.domain1.com

    Does anyone have any idea how I may approach this?
    Cheers all.

  2. #2
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check $_SERVER['PHP_SELF']. This should give you the absolute URL. However, depending on your server configuration, you might always get the same URL. And then there's nothing to be done about that, except changing the configuration.

    Vincent

  3. #3
    SitePoint Addict phptek's Avatar
    Join Date
    Jun 2002
    Location
    Wellington, NZ
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers For that Vincent.

    However, I just found this elsewhere and it did the job exactly:

    if(strpos($HTTP_REFERER,"http://www.domain1.com")===false)
    {
    header("Location: http://subdomain.domain2.com");
    }

    Cheers again.

  4. #4
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Apache, isn't it?

    I think that if you try this with IIS, you'll find that it doesn't work. This might not be a problem for you, but it's good to know anyhow.

    Vincent


Bookmarks

Posting Permissions

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