title: Apache redirectMatch, add query string
body: <p>I'm redirecting from a subfolder to a subdomain. This is working fine, but I'd like to append a query string at the end of my url to track how many people have been redirected.</p>
  <pre><code>RewriteRule ^/my-folder/(.*)$ https://subdomain.example.com/?ref=my_ref [R=302,L]
  </code></pre>
  <p>The above should be working according to <a href="https://simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/" rel="nofollow noreferrer">this article</a>, but it doesn't.</p>
  <p>It just redirects me to <code>https://subdomain.example.com/</code></p>
  <p>How do I add <code>?ref=my_ref</code> during a redirect?</p>
  <p>Edit:
  The full .htaccess</p>
  <pre><code>#to remove old /forum/topic and keep /topic
  RewriteRule ^forum/topic/(.*)$ /topic/$1 [L,NC,R=301]
  
  ### Rewrites Engine
  &lt;IfModule mod_rewrite.c&gt;
  Options -MultiViews
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /404error.php [L,NC]
  
  RewriteRule ^/my-folder/(.*)/?$ https://subdomain.example.com/?ref=$1 [R=302,L,NC]      
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  </code></pre>