window.location = "https://" + window.location.hostname + window.location.pathname + window.location.search;
You might wanna test if window.location.href doesn’t start with “https” before doing that, so you don’t redirect unless you have to.
Why would use JS instead of PHP? Or .htaccess?
Maybe you’d like it to be triggered by a user event, there’s never only 1 right way to do something
This is what I was using before, although Chris’s way is far better
window.location = window.location.href.substr(0,4) + “s” + window.location.href.substr(4,250);
Don’t forget about
location.hash
!You also can use
Thanks TeMc, this was exactly what I needed…worked like a charm!
try
window.location = “https://” + window.location.hostname + window.location.pathname + window.location.search;