I want to add a modified link on a 404 page because I moved the permalink structure from domain.tld/category/title to domain.tld/title. Now when a visitor found an old link to domain.tld/category/title she/he will see the 404 page and there should be a dynamic link to domain.tld/title. This link should be generated if window.location.href contains five "/" (because of http://www.domain.tld/category/title/ has five "/" and my new permalink structure won't have five "/" but only four "/". I know I can replace (remove) the category part with this code:
function geturl(){
var url = window.location.href;
alert(url.replace('/category/', '/'));
}
The problem with that is that I have to define a static category name but it could be anything. How to get rid of /category/ part dynamically when there are five "/" in window.location.href?