title: JavaScript - htaccess - ErrorDocument - url rewrite - get variables from rewritten URI
body: <p>I have a "client-side" problem regarding retrieval of variables from a re-written request. There must be a simple way to achieve this, I just don't know how.</p>
  
  <p>The objective is to have JavaScript (client-side) handle server "error" responses, like: 403, or 404.</p>
  
  <p>These are the relevant code snippets that I have:</p>
  
  <p><strong>.htaccess</strong><br></p>
  
  <pre><code>ErrorDocument 404 /lib/dbug.htm?fail=404
  </code></pre>
  
  <p><br>
  <strong>JavaScript</strong><br></p>
  
  <pre><code>console.log(document.location.search)
  </code></pre>
  
  <p><br>
  When I test it in the browser, with i.e: <code>apache.dev/foo.bar</code> - the console log shows an empty string.</p>
  
  <p>I understand this is because the current "document path" is "/foo.bar" - with no query-string at all; however, the response URL was rewritten as shown above.</p>
  
  <p>There may be issues with my <code>.htaccess</code> code, and if so, please advise?<br>
  I think that the problem could be solved by somehow setting a response-header in the <code>.htaccess</code> and retrieve that with JavaScript, somehow.. Either that or somehow get the <code>document.responseCode</code> ?</p>
  
  <ul>
  <li>Is it possible to retrieve the re-written query-string from anywhere?</li>
  <li>If not, can I set a header in the .htaccess and have JavaScript retrieve this?</li>
  </ul>
  
  <p>Been at this for hours, no luck. If anyone has an idea of how to achieve this, I would appreciate the input.</p>