title: How redirect wrong querystring to custom errorpage + 404 status
body: <p>I would like to redirect users that use a wrong querystring in the URL to a custom error page while ALSO giving a 404 status through the .htaccess directive </p>
  
  <pre><code>ErrorDocument 404 http://www.domain.com/404.php
  </code></pre>
  
  <blockquote>
    <blockquote>
      <p>EDIT: this does not give 404 but 302!!!  The "http://www.domain.com"
      causes a redirect. Just the local path gives a 404. See also <a href="http://httpd.apache.org/docs/2.0/mod/core.html#errordocument" rel="nofollow">http://httpd.apache.org/docs/2.0/mod/core.html#errordocument</a></p>
    </blockquote>
  </blockquote>
  
  <p>Therefore I made a script in the request-receiving index.php that determines if the querystring is not valid and if so, gives this command:</p>
  
  <pre><code>header("HTTP/1.0 404 Not Found");
  </code></pre>
  
  <p>BUT this does not redirect via the .htaccess directive ErrorDocument but just gives a 404 status to the visitor.</p>
  
  <p>And when using <code>header("Location: 404.php")</code> you get a 302 status, and when using <code>header("Location: 404.php", true, 404)</code> the status is 404 but it does not go to the custom 404.php page.</p>
  
  <p>Now I use </p>
  
  <pre><code>header ("Location: ", true, 404); 
  echo "The URL you use doesn't lead to an existing page, etc.";
  </code></pre>
  
  <p>But this was not the original plan... How would I make users that use a wrong querystring in the URL redirect to the custom error page while also giving a 404 status through the .htaccess directive ErrorDocument, or is this not possible?</p>