I have a url http://xyz.in/pqr/v/index.php and I want to get only http://xyz.in/pqr/v/ so how can I remove index.php from url.
5 Answers
Try this.
var host = window.location.protocol+'//'+window.location.host+'/'
alert(host);
if you want to avoid '/' at last, You can use this
var host2 = window.location.protocol+'//'+window.location.host
SEE THIS FIDDLE DEMO
1 Comment
yashhy
but how will you get /pqr/v/ paths as mentioned in the question?
you can use .replace() function
try with this FIDDLE
var getUrl = "http://xyz.in/pqr/v/index.php";
var change = getUrl.replace('index.php','');
NOTE : If your 'index.php' name is static
Comments
try this
function GetBaseUrl() {
try {
var url = location.href;
var start = url.indexOf('//');
if (start < 0)
start = 0
else
start = start + 2;
var end = url.indexOf('/', start);
if (end < 0) end = url.length - start;
var baseURL = url.substring(start, end);
return baseURL;
}
catch (arg) {
return null;
}
}
url.split('/').pop();var arr = url.split('/); arr.pop(); arr = arr.join('/');