title: Redirect Spam Query String URLs Created After Hack
body: <p>One of my sites was hacked and after that thousands of urls were showing up.</p>
  
  <p>I want to edit my htaccess so that all urls that have /?x= are redirected to page without the query string.</p>
  
  <p>The site is a word press site so cant redirect all urls with a query string or the site stops working properly.</p>
  
  <p>Basically I need:</p>
  
  <pre><code>www.example.com/?x=spamurl
  </code></pre>
  
  <p>to redirect to</p>
  
  <pre><code>www.example.com
  </code></pre>
  
  <p>and any deep page that includes ?x= </p>
  
  <pre><code>www.example.com/category/?x=spamurl
  </code></pre>
  
  <p>to redirect to</p>
  
  <pre><code>www.example.com/category/
  </code></pre>
  
  <p>This is my current htaccess</p>
  
  <pre><code>   # BEGIN WordPress
      &lt;IfModule mod_rewrite.c&gt;
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.php$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
      RewriteCond %{QUERY_STRING} x=
      RewriteRule ^$ http://www.example.com/? [R=301,L]
      &lt;/IfModule&gt;
  
      # END WordPress
  </code></pre>
  
  <p>As you can see I have managed to get any url with ?x= after the main url to redirect to the main page but I cant figure out how to do this when ?x= shows after category pages etc..</p>
  
  <p>Is there coding that can redirect ALL urls that include ?x= to a 404 page without causing an issue for wordpress files?</p>
  
  <p>Many Thanks</p>
  
  <p>Scott</p>