Why is localhost added to all my links ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hal Halloway

    Why is localhost added to all my links ?

    Not sure if this is a php, mysql, or apache issue. I use win2k and I
    have AMP on my system as a localhost. I use this to test PHP/MYSQL
    scripts I write on my local PC.

    I render a URL w/PHP by reading the URL string from a mysql field, eg.
    on the php web page it shows as eg. www.yahoo.com link

    But when I click the link I see that "localhost" is added to the URL
    and it goes nowhere. ie. it get localhost added to the front -
    localhost/www.yahoo.com

    Is there a setting somewhere so that the link is exactly what the link
    is and localhost is not added.

    Thanks
  • Michael Fesser

    #2
    Re: Why is localhost added to all my links ?

    .oO(Hal Halloway)
    [color=blue]
    >I render a URL w/PHP by reading the URL string from a mysql field, eg.
    >on the php web page it shows as eg. www.yahoo.com link
    >
    >But when I click the link I see that "localhost" is added to the URL
    >and it goes nowhere. ie. it get localhost added to the front -
    >localhost/www.yahoo.com
    >
    >Is there a setting somewhere so that the link is exactly what the link
    >is and localhost is not added.[/color]

    Relative URLs are expanded with the current hostname. If you want to
    link to external servers the URL has to start with http(s)://.

    Micha

    Comment

    • Janwillem Borleffs

      #3
      Re: Why is localhost added to all my links ?

      Hal Halloway wrote:[color=blue]
      > I render a URL w/PHP by reading the URL string from a mysql field, eg.
      > on the php web page it shows as eg. www.yahoo.com link
      >
      > But when I click the link I see that "localhost" is added to the URL
      > and it goes nowhere. ie. it get localhost added to the front -
      > localhost/www.yahoo.com
      >
      > Is there a setting somewhere so that the link is exactly what the link
      > is and localhost is not added.
      >[/color]

      When you construct the anchors without the "http://" prefix, all the targets
      are expected to be on the same server.


      JW



      Comment

      • Mark

        #4
        Re: Why is localhost added to all my links ?

        Hal Halloway wrote:

        [color=blue]
        > But when I click the link I see that "localhost" is added to the URL
        > and it goes nowhere. ie. it get localhost added to the front -
        > localhost/www.yahoo.com[/color]

        looks like PHP has a couple of rules:

        1. if you prefix a URL with http:// or just a /, then it leaves it alone.

        i.e "http://www.happyhappyb unnies.com"
        "/showerror.php?e rr=342"


        2. if you do neither of these, it prefixes them with a host name and /.

        [color=blue]
        > Is there a setting somewhere so that the link is exactly what the link
        > is and localhost is not added.[/color]

        best choice would be to prefix full URLs with http:// and relative URLs
        with /.

        PHP does have a mechanism via which you can control what markup elements
        it modifies on output, which somehow ties into the url_rewriter.ta gs entry
        in the php.ini file. i haven't studied this too much, so i'm not 100%
        certain how it works.

        good ruck!

        mark.

        [color=blue]
        > Thanks[/color]

        --
        I am not an ANGRY man. Remove the rage from my email to reply.

        Comment

        • Michael Fesser

          #5
          Re: Why is localhost added to all my links ?

          .oO(Mark)
          [color=blue]
          >Hal Halloway wrote:
          >[color=green]
          >> But when I click the link I see that "localhost" is added to the URL
          >> and it goes nowhere. ie. it get localhost added to the front -
          >> localhost/www.yahoo.com[/color]
          >
          > looks like PHP has a couple of rules:[/color]

          It's not a PHP issue.
          [color=blue]
          > 1. if you prefix a URL with http:// or just a /, then it leaves it alone.
          >
          > i.e "http://www.happyhappyb unnies.com"
          > "/showerror.php?e rr=342"
          >
          > 2. if you do neither of these, it prefixes them with a host name and /.[/color]

          The user agent (browser) expands URLs if necessary, not the server. Have
          a look at the generated HTML to see what PHP did send to the browser.
          [color=blue]
          > PHP does have a mechanism via which you can control what markup elements
          >it modifies on output, which somehow ties into the url_rewriter.ta gs entry
          >in the php.ini file. i haven't studied this too much, so i'm not 100%
          >certain how it works.[/color]

          This only applies to session handling.

          Micha

          Comment

          Working...