Replace fragile hack with proper URL parsing & pathname matching