Converting relative URLs to absolute?

Discussion in 'Ruby' started by Nick Woolley, Jun 30, 2005.

  1. Nick Woolley

    Nick Woolley Guest

    Hi,

    Whilst porting some perl code which uses the URI module:

    # convert a relative url to an absolute url
    my $val = "../some/relative/url.html";
    my $target_url = "http://www.somehost.net/blah/page.html";
    my $uri = URI->new_abs($val, $target_url);

    # $uri is 'http://www.somehost.net/some/relative/url.html'

    - I discovered that there seems to be no standard library equivalent in
    ruby, i.e. for converting relative URIs to absolute ones... or am I just
    not looking in the right places? (I looked on Google, ruby-doc.org, in
    'Pickaxe', etc.)

    Thanks,

    Nick


    ___________________________________________________________
    How much free photo storage do you get? Store your holiday
    snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
     
    Nick Woolley, Jun 30, 2005
    #1
    1. Advertising

  2. Nick Woolley

    Eric Hodel Guest

    On 29 Jun 2005, at 18:05, Nick Woolley wrote:

    > Hi,
    >
    > Whilst porting some perl code which uses the URI module:
    >
    > # convert a relative url to an absolute url
    > my $val = "../some/relative/url.html";
    > my $target_url = "http://www.somehost.net/blah/page.html";
    > my $uri = URI->new_abs($val, $target_url);
    >
    > # $uri is 'http://www.somehost.net/some/relative/url.html'
    >
    > - I discovered that there seems to be no standard library
    > equivalent in ruby, i.e. for converting relative URIs to absolute
    > ones... or am I just not looking in the right places? (I looked on
    > Google, ruby-doc.org, in 'Pickaxe', etc.)


    URI does this

    $ irb
    irb(main):001:0> require 'uri'
    => true
    irb(main):002:0> original_uri = URI.parse "http://www.somehost.net/
    blah/page.html"
    => #<URI::HTTP:0x19999c URL:http://www.somehost.net/blah/page.html>
    irb(main):003:0> puts original_uri + "../some/relative/url.html"
    http://www.somehost.net/some/relative/url.html
    => nil


    --
    Eric Hodel - - http://segment7.net
    FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
     
    Eric Hodel, Jun 30, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Flip

    relative vs absolute URLs?

    Flip, Nov 24, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    458
  2. Kyle James Matthews

    Relative vs. absolute URLs

    Kyle James Matthews, May 11, 2004, in forum: HTML
    Replies:
    3
    Views:
    621
  3. theo

    Relative/Absolute URLS

    theo, Feb 7, 2005, in forum: HTML
    Replies:
    17
    Views:
    852
  4. Nathan Sokalski

    Converting Relative URLs into Absolute URLs

    Nathan Sokalski, Aug 11, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    764
    Sriram Srivatsan
    Aug 12, 2008
  5. Rudi Ahlers
    Replies:
    11
    Views:
    846
    Aaron Bertrand [MVP]
    Apr 11, 2004
Loading...

Share This Page