title: How to fix Cross-Origin Request Blocked for ajax request (in Firefox)?
body: <p>I get the following error from an ajax request in Firefox:</p>
  
  <pre><code>Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.example.org/php/save.php. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
  </code></pre>
  
  <p>I tried to find out why this is happening. It is strange since </p>
  
  <ul>
  <li>the script works totally fine on my subdomain on the same server</li>
  <li>the file accessed is on the same server</li>
  </ul>
  
  <p>I also tried </p>
  
  <pre><code>xhttp = new XMLHttpRequest({mozSystem: true});
  </code></pre>
  
  <p>as suggested here: <a href="https://stackoverflow.com/a/22392080">https://stackoverflow.com/a/22392080</a></p>
  
  <p>But that did not help either.</p>
  
  <p>I am using the following command to open the request:</p>
  
  <pre><code>xhttp.open('POST', '/php/save.php', true);
  </code></pre>
  
  <p>I found a number of other solution for when the file is on another server:</p>
  
  <pre><code>&lt;IfModule mod_headers.c&gt;
    Header set Access-Control-Allow-Origin "*"
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>But I don't see why I should do this if the file is actually on the same server...</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I removed the following two lines from my <code>.htaccess</code> file and now it works.</p>
  
  <pre><code>RewriteCond     %{HTTP_HOST}    !^www\.example\.org$                        [NC] 
  RewriteRule     .?              http://www.example.org%{REQUEST_URI}        [R=301,L]
  </code></pre>
  
  <p>Though I am not sure why... maybe the adding of <code>www.</code> works like moving to a subdomain?</p>
  
  <p>What would I have to add to my <code>.htaccess</code> file to get it to work with ajax and the rewrite?</p>