title: htaccess mod_rewrite - Trailing Slash and loop of redirects
body: <p>Here is my htaccess code:</p>
  
  <pre>RewriteEngine On
  RewriteRule ^s/(.*)/(.*) /index.php?search=$1&category=$2 [L,QSA]
  
  RewriteCond %{QUERY_STRING} ^search=([A-Za-z0-9\+]+)$
  RewriteRule ^(.*)$ /s/%1/? [R=301,L]
  
  RewriteCond %{QUERY_STRING} ^search=([A-Za-z0-9\+]+)&category=([A-Za-z0-9\+]+)$
  RewriteRule ^(.*)$ /s/%1/%2/? [R=301,L]</pre>
  
  <p>I need to make a rewrite rule like this:</p>
  
  <pre>http://mywebsite.com/s/query+term => http://mywebsite.com/?search=query+term
  
  OR if there is a category
  
  http://mywebsite.com/s/query+term/Category => http://mywebsite.com/?search=query+term&category=Category</pre>
  
  <p>I need also to redirect all the old urls to the new one.</p>
  
  <p>With this rules all that I can obtain is to have the search term and category name joined togheter. In a nutshell it is as if I had always:<br/>
  <code><a href="http://mywebsite.com/?search=query+term/Category" rel="nofollow">http://mywebsite.com/?search=query+term/Category</a></code>
  <br/>
  If I remove all the conditions (RewriteCond), leaving only the rewrite rule with the addition of a trailing slash:</p>
  
  <pre>RewriteEngine On
  RewriteRule ^s/(.*)/(.*)/ /index.php?search=$1&category=$2 [L,QSA]</pre>
  
  <p>Reaching the url of my interest in a direct way, the whole thing works. But I will not have the redirect..</p>
  
  <p>So I have tried to set a rule like this:</p>
  
  <pre>RewriteEngine On
  RewriteRule ^s/(.*)/(.*)/ /index.php?search=$1&category=$2 [L,QSA]
  
  RewriteCond %{QUERY_STRING} ^search=([A-Za-z0-9\+]+)$
  RewriteRule ^(.*)$ /s/%1/? [R=301,L]
  
  RewriteCond %{QUERY_STRING} ^search=([A-Za-z0-9\+]+)&category=([A-Za-z0-9\+]+)$
  RewriteRule ^(.*)$ /s/%1/%2/? [R=301,L]</pre>
  
  <p>But with this rule I get just a loop of redirects.</p>