how to constract absolute URL from relative URL string
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hello all
how can i get absolute URL from relative URL string like "../foo.html"
like like "http://www.mysite.com/stuff/foo.html"
thanks
how can i get absolute URL from relative URL string like "../foo.html"
like like "http://www.mysite.com/stuff/foo.html"
thanks
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
You will need the base URL as well, like "http://www.mysite.com/stuff/subfolder/". Then just use one of the URL constructors that takes a URL object as the first parameter:
Note that the base URL needs a trailing / if it is a folder, or the "subfolder" part will be considered as a file, and "stuff" will be considered as the current folder.
Note that the base URL needs a trailing / if it is a folder, or the "subfolder" part will be considered as a file, and "stuff" will be considered as the current folder.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
ben josh
Ranch Hand
Posts: 620
1
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
but what if i have only the site host url like
"www.mysite.com"
and then i have in the links only the relative URl like :
..\..\foo.html
can i somehow construct full uri ?
"www.mysite.com"
and then i have in the links only the relative URl like :
..\..\foo.html
can i somehow construct full uri ?
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
This code should work
[ September 06, 2008: Message edited by: Rene Larsen ]
[ September 06, 2008: Message edited by: Rene Larsen ]
Regards, Rene Larsen
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If you don't know the current URL, you can't of course determine the absolute URL of any relative URL. For instance, ../foo.html will have a different absolute URL if found on www.mysite.com (www.mysite.com/foo.html), www.mysite.com/mypath (www.mysite.com/foo.html) or www.mysite.com/mypath/mysubpath (www.mysite.com/mypath/foo.html).
So your first step is: determine the full current URL, or you can't do a single thing. If you don't know the domain, you can actually add any domain and later cut it off again. "localhost" tends to be a good one
So your first step is: determine the full current URL, or you can't do a single thing. If you don't know the domain, you can actually add any domain and later cut it off again. "localhost" tends to be a good one

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
| Won't you be my neighbor? - Fred Rogers. tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |












