Redirect 404 to external domain, preserving URI, using .htaccess
<p>Spent a while on this and searched a lot. Found questions and answers that almost covered what I need, but not quite...</p>

<p>In a nutshell: Trying to redirect a user to an external domain when they receive a 404, preserving the URI, <strong>using only .htaccess</strong>.</p>

<p>Considerations:</p>

<ul>
<li>Apache does not know of the files on the server, it requests them dynamically from a CMS.</li>
<li>The requested URI <em>may</em> have funky characters in it, e.g. ";" "="</li>
<li>Need to avoid any server side scripting (e.g. php).</li>
</ul>

<p>Required behaviour:</p>

<ul>
<li>User requests a URL</li>
<li>Server responds with a 404</li>
<li>User is transparently redirected to an external domain, preserving the URI</li>
</ul>

<blockquote>
  <p>Example 1:</p>
  
  <ul>
  <li>User requests: www.example.com/no/Page</li>
  <li>Server responds with 404</li>
  <li>User is redirected to: www.newdomain.com/no/Page</li>
  </ul>
  
  <p>Example 2:</p>
  
  <ul>
  <li>User requests: www.example.com/url;=xyz</li>
  <li>Server responds with 404</li>
  <li>User is redirected to: www.newdomain.com/url;=xyz</li>
  </ul>
</blockquote>

<p>Can this be implemented <strong>only</strong> with .htaccess?</p>

<p>Trying something along the lines of:</p>

<pre><code>RewriteEngine On

ErrorDocument 404 /404.html?u=/the/Requested/URI

RewriteCond %{REQUEST_URI} ^/404.html [NC]
RewriteCond %{QUERY_STRING} ^u=(.*)
RewriteRule (.*) http://www.newdomain.com%1? [NC,NE,L,R=301,E=nocache:1]
</code></pre>

<p>This mostly works, but only with the hardcoded query string... can't get it included dynamically.</p>

<p>Any ideas how to achieve this (if at all)? </p>