title: Redirect all 404 errors with 301 to HomePage in Wordpress using .htaccess (including reserved wordpress terms)
body: <p>I have an old Wordpress website with a lot of pages. I changed to a single page website and I want to redirect all 404 errors with 301 redirect to Homepage.</p>
  
  <p>I don't want to use plugins or change the 404 page. I want to do it in the .htaccess file.</p>
  
  <p>This is the code I tried:</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . / [L,R=301]
  </code></pre>
  
  <p>This works perfect with almost all cases, like:</p>
  
  <pre><code>www.site.com/111 -&gt; redirect 301 -&gt; www.site.com/
  www.site.com/abcd/222.html -&gt; redirect 301 -&gt; www.site.com/
  </code></pre>
  
  <p>But it didn't work in the cases below:</p>
  
  <pre><code>www.site.com/?p=123
  www.site.com/abc/?attachment_id=abc
  </code></pre>
  
  <p>The problem is that this don't work with URLs that contains Wordpress terms:
  <a href="https://codex.wordpress.org/WordPress_Query_Vars" rel="nofollow">https://codex.wordpress.org/WordPress_Query_Vars</a></p>
  
  <p>Does anybody know how to solve this problem?</p>