How can I redirect requests based on host?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jay Shen

    How can I redirect requests based on host?

    Hi,

    I have two domains pointing to the same ISP hosted web site.
    How can I redirect request for www.domain2.com to a sub-folder using header
    field "host"?
    Thanks a lot...

    J-



  • Alan Little

    #2
    Re: How can I redirect requests based on host?

    Carved in mystic runes upon the very living rock, the last words of Jay
    Shen of comp.lang.php make plain:
    [color=blue]
    > I have two domains pointing to the same ISP hosted web site.
    > How can I redirect request for www.domain2.com to a sub-folder using
    > header field "host"?[/color]

    In your index file:

    if (ereg("domain2. com", $_SERVER['HTTP_HOST'])) {
    header("Locatio n: /subfolder/");
    }

    After that of course you'll have to make sure all your links include the
    subfolder path.

    --
    Alan Little
    Phorm PHP Form Processor

    Comment

    • Shawn Wilson

      #3
      Re: How can I redirect requests based on host?

      Alan Little wrote:[color=blue]
      >
      > Carved in mystic runes upon the very living rock, the last words of Jay
      > Shen of comp.lang.php make plain:
      >[color=green]
      > > I have two domains pointing to the same ISP hosted web site.
      > > How can I redirect request for www.domain2.com to a sub-folder using
      > > header field "host"?[/color]
      >
      > In your index file:
      >
      > if (ereg("domain2. com", $_SERVER['HTTP_HOST'])) {
      > header("Locatio n: /subfolder/");
      > }
      >
      > After that of course you'll have to make sure all your links include the
      > subfolder path.[/color]

      I've heard that some browsers have trouble with the Location header if you don't
      include the full url, but I'm not sure if which ones. You might want to try:

      header("Locatio n: http://www.domain2.com/subfolder/");

      --
      Shawn Wilson
      shawn@glassgian t.com

      Comment

      • Eto Demerzel

        #4
        Re: How can I redirect requests based on host?

        In article <KOhob.698$u22. 304@newssvr14.n ews.prodigy.com >, Jay Shen's
        output was...[color=blue]
        > Hi,
        >
        > I have two domains pointing to the same ISP hosted web site.
        > How can I redirect request for www.domain2.com to a sub-folder using header
        > field "host"?[/color]

        Surely your ISP can set up name-based virtual hosts under Apache?


        Comment

        • John Dunlop

          #5
          Re: How can I redirect requests based on host?

          Shawn Wilson wrote:
          [color=blue]
          > I've heard that some browsers have trouble with the Location header
          > if you don't include the full url,[/color]

          The field value of the Location HTTP header must consist of an
          absolute URL; a relative URL would contravene RFC2616, sec. 14.30.
          Resultantly, relying on relative URLs working is unwise, despite
          applications supporting them.

          --
          Jock

          Comment

          • Eric Ellsworth

            #6
            Re: How can I redirect requests based on host?

            Similarly, if you're running Apache, you can do this without having to worry
            about links by using mod_rewrite and checking what the hostname specified in
            the URL was. Check out the documentation for mod_rewrite:

            http://httpd.apache.org/docs/mod/mod_rewrite.html (Apache 1.3)
            http://httpd.apache.org/docs-2.0/mod/mod_rewrite.html (Apache 2.0)

            Hope that helps.

            EE

            "Eto Demerzel" <eto.demerzel@f ijivillage.com> wrote in message
            news:MPG.1a0c9d 4ca2829dbe98972 a@news-text.blueyonder .co.uk...[color=blue]
            > In article <KOhob.698$u22. 304@newssvr14.n ews.prodigy.com >, Jay Shen's
            > output was...[color=green]
            > > Hi,
            > >
            > > I have two domains pointing to the same ISP hosted web site.
            > > How can I redirect request for www.domain2.com to a sub-folder using[/color][/color]
            header[color=blue][color=green]
            > > field "host"?[/color]
            >
            > Surely your ISP can set up name-based virtual hosts under Apache?
            >
            > http://httpd.apache.org/docs-2.0/vhosts/[/color]


            Comment

            Working...