title: page-redirecting script gives me a redirect loop
body: <p>My webhost shows every page with and without the www. subdomain, but the URL with the subdomain and the URL without the subdomain take me to two different locations (there is no redirect). The problem I have with this is that if I have cookies saved on example.com/website.html, they would not be saved on www.example.com/website.html. My solution was a script that checked if the hostname of the webpage had the www. prefix, and if it did, it would redirect to the same page, but without the prefix.</p>
  
  <p>The code below was my solution, and it works, but the webpage will continuously go into a redirect loop after it has changed from www.example.com/website.html to example.com/website.html</p>
  
  <pre><code>if (document.location.host = 'www.example.com') {
      window.location.href = "http://example.com";
  }
  </code></pre>
  
  <p>I would rather not use the .htaccess file because I do not think my webhost has it properly configured, but I am willing to try using it.</p>