jan199674
jan199674

Reputation: 753

Remove current url path and replace?

How do i delete the current url path and return to index.php? I have a link to a page in a subfolder - the generated url could look like this:

http://localhost/site/pages/home.php

How do i erase that url path and return to index.php in root http://localhost/site/index.php

So far i have this which will show index.php in root, but it doesnt delete the original url path containing home-php?

$('#btn').click(function() {    
   window.location.href='index.php';
}); 

The url looks like this http://localhost/site/pages/home.php/site/index.php

Upvotes: 1

Views: 4244

Answers (1)

Clément Andraud
Clément Andraud

Reputation: 9269

Just reload the page and redirect the user to the good page :

window.location.href='/index.php';

EDIT :

Or try to rebuild your url :

// If URL is http://www.somedomain.com/account/search?filter=a#top

window.location.pathname // /account/search

// For reference:

window.location.host     // www.somedomain.com (includes port if there is one)
window.location.hostname // www.somedomain.com
window.location.hash     // #top
window.location.href     // http://www.somedomain.com/account/search?filter=a#top
window.location.port     // (empty string)
window.location.protocol // http:
window.location.search   // ?filter=a  

And redirect with the full url, not just/index.php

Upvotes: 2

Related Questions