Have a URL, how to retrieve its path part?
http://www.costo.com/test1/test2
How to get "test1/test2"
Most servers use the well-known port numbers for HTTP and HTTPS , so most HTTP URLs omit the port number. A path. The path identifies the specific resource in the host that the web client wants to access. For example, /software/htp/cics/index.
var newURL="http://www.example.com/index.html/homePage/aboutus/"; console. log(newURL); var splitURL=newURL. toString(). split("/"); console.
You want something like this:
String path = new URL("http://www.costo.com/test1/test2").getPath();
Actually that'll give you /test1/test2
. You'll just have to remove the first /
to get what you want:
path = path.replaceFirst("/", "");
Now you'll have test1/test2
in path
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With