title: Using htaccess to force a trailing slash before the ? with a query string?
body: <p>I have the following in my htaccess file:</p>
  
  <pre><code>RewriteEngine On
  RewriteBase /
  
  # Check to see if the URL points to a valid file
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  # Trailing slash check
  RewriteCond %{REQUEST_URI} !(.*)/$
  
  # Add slash if missing &amp; redirect
  RewriteRule ^(.*)$ $1/ [L,R=301]
  
  # Check to see if the URL points to a valid file
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  # Send to index.php for clean URLs
  RewriteRule ^(.*)$ index.php?/$1 [L]
  </code></pre>
  
  <p>This does work.  It hides index.php, and it adds a trailing slash... except when there is a query string.</p>
  
  <p>This URL:</p>
  
  <pre><code>http://example.com/some-page
  </code></pre>
  
  <p>gets redirected to:</p>
  
  <pre><code>http://example.com/some-page/
  </code></pre>
  
  <p>but this URL:</p>
  
  <pre><code>http://example.com/some-page?some-var=foo&amp;some-other-var=bar
  </code></pre>
  
  <p>does not get redirected.  I would like for the above to be sent to:</p>
  
  <pre><code>http://example.com/some-page/?some-var=foo&amp;some-other-var=bar
  </code></pre>
  
  <p>I've reached the limits of my understanding of redirects with this.  If you have a working answer, I would really appreciate a walkthrough of what every line is doing and why it works.  Double bonus awesomeness for an explanation of why what I have right now doesn't work when there is a query string involved.</p>