title: Remove trailing '/' from the end of URL
body: <p>So I have the following bit of code which works to some extent. </p>
  
  <pre><code>var url = window.location.protocol + "//" + window.location.host + window.location.pathname;
  
  var sanitized = url
      .replace(/^https\:\/\//, '') // remove the leading http:// (temporarily)
      .replace(/\/+/g, '/')       // replace consecutive slashes with a single slash
      .replace(/\/+$/, '');       // remove trailing slashes
  
  url = 'https://' + sanitized;
  
  window.onload = function urlChange(){
      location.replace(url);
  }
  </code></pre>
  
  <p>The only issue is that once the url gets changed the page keeps reloading as if I have an infinite loop going on.</p>
  
  <p>Any ideas? </p>
  
  <p>Thanks!</p>