title: non-www to www client side redirection with javascript
body: <p>How can I redirect the following url in javascript :</p>
  
  <pre><code>http://example.com/?querystrings
  </code></pre>
  
  <p>=></p>
  
  <pre><code>http://www.example.com
  </code></pre>
  
  <p>I want to redirect my url without www to www discarding the querystrings.</p>
  
  <p>I know how to do it server side using mod_rewrite, I am working on a client side js app, where I need this.</p>
  
  <p>Is this type of redirection possible with JS?</p>
  
  <p>My code so far :</p>
  
  <pre><code>&lt;body onload="addwww()"&gt;
  &lt;script&gt;
  function addwww() {
   location.href="http://www.example.com";
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>it redirects the entire page to www with redirect loop error. how can I redirect only when there is no www in the url?</p>
  
  <p>Thanks!</p>