• Post Reply Bookmark Topic Watch Topic
  • New Topic

changing a relative url to an absolute url  RSS feed

 
mj zammit
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I need to change all the relative urls found on a webpage to absolute urls.

Now i know that if the webpage's name is "http://www.hello.com/index.html" then for every relative url found on the webpage, example "tree.html", i must append to it the hostname of the webpage, that is, "http://www.hello.com/tree.html"

But what if that is not the hostname it needs?
For example what if "http://www.hello.com" is a page that is part of the main page called "http://www.greetings.com" and therefore every relative url found on the "http://www.hello.com" page require the hostname of the "http://www.greetings.com" page.
How can I accomodate this?

I am using HttpClient and i am not sure if it does this automatically.

Any comments will be greatly appreciated

MJ
 
Joseph Macer
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, relative URLs can save a lot of time & headache by making your website more portable. Where are these URLs, specifically, that need changing? In your HTML? Unless you're running a huge website (in which case you'd already have a better solution) I'd just do a quick search/replace on a by-file basis. Put careful thought into why you want absolute URLs, maybe your webpage just needs restructuring.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!