Added urlparse to javascript for correct redirect