Converting relative URLs to absolute?

N

Nick Woolley

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
 
E

Eric Hodel

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top