The jQuery you posted does this:
Find all <a>
elements
That have an href attribute
That contains the phrase: whatever is in the address bar
And for each of those that match, add class "active"
Because the jQuery searches for a tags that contain what is in the address bar, you should alright if the address contains a subset of what is in the a tag's href.
There is also the possibility that a leading slash could be a problem. This will remove the first character from the "pathname" - so, for example, if the URL is "/index.html" this will search for "index.html".
$("a[href*='" + window.location.pathname.slice(1) + "']").addClass("active");
If this answer does not help, please post a comment below the answer providing more information (i.e. WHY does this answer not solve the problem - what was missed?) so that other viewers can assist.