title: Redirect URL using javascript
body: <p>is it possible to redirect the hostname of the URL using javascript?</p>
  
  <p>If URL contains "content/articles", it should remain in the same URL. Otherwise, it should redirect all other URLs from www to www1.</p>
  
  <p>I think i got the <strong>"/content/articles"</strong> part but <strong>window.location.replace</strong> doesnt seem to work.</p>
  
  <p>For example: </p>
  
  <ul>
  <li><a href="https://www.abc.com.sg/content/articles" rel="nofollow noreferrer">https://www.abc.com.sg/content/articles</a> will remain the same URL.</li>
  <li><a href="https://www.abc.com.sg" rel="nofollow noreferrer">https://www.abc.com.sg</a> redirect to <a href="https://www1.abc.com.sg" rel="nofollow noreferrer">https://www1.abc.com.sg</a></li>
  </ul>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script type="text/javascript"&gt;
   window.onload = function() {
           if (window.location.href.indexOf("/content/articles") &gt; -1) {
            // Do not redirect                                
           } else {
     // Redirect from www to www1
     window.location.replace(window.location.protocol + "//" + window.location.hostname.replace("www", "www1")+window.location.pathname);
    }
          }
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>