title: Automatic redirection to https with port change
body: <p>Similar to this <a href="https://stackoverflow.com/questions/4954768/automatic-redirection-to-https">question</a>, how can I change the port too?</p>
  
  <pre><code>if (window.location.href.indexOf('http://')==0)
            window.location=window.location.href.replace('http://','https://');
  </code></pre>
  
  <p>For example, I want to change <code>http://localhost:8080/test/</code> to <code>https://localhost:8443/test/</code>, but right now it is only changing it to <code>https://localhost:8080/test/</code></p>
  
  <p>Is there a way to change it without hardcoding it? Currently I can hard code it like this <code>window.location = "https:localhost:8443/test/"</code>, but then I would have to do that for every unique page in test, and that could get to be a hassle.</p>
  
  <p>Instead, is there a way to automatically change the port?</p>