title: rewriteCond request with htaccess
body: <p>I would like to accomplish the followings (rewrite not redirect):</p>
  
  <ol>
  <li><code>searchPage.php?crs_category=variable</code> like <code>searchPage.php?crs_category=business</code> to <code>category/business</code> or <code>category/business/</code> case in-sensitive </li>
  </ol>
  
  <p>You can also directly access <code>category/name</code> which is the rewrite of searchPage</p>
  
  <ol start="2">
  <li><code>index.php/name</code> to <code>page/name</code> case in-sesitive. note this is a rewrite not a redirect and i would like access the <code>index.php/name</code> just with a clean url.</li>
  </ol>
  
  <p>You can also directly access <code>page/name</code> which is the rewrite of <code>index.php/name</code></p>
  
  <p>Note:
  - it needs to take into account spaces such as if a user click on <code>searchPage.php?crs_category=html%20and%css</code> it would rewrite the url to <code>category/html and css</code></p>
  
  <p>Tried:</p>
  
  <pre><code>RewriteEngine On
  RewriteBase /
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  
  RewriteCond %{THE_REQUEST} /searchPage.php\?crs_category=([^\s]+) [NC]
  RewriteRule ^category/%1? [NE,NC,R,L]
  RewriteRule ^category/([^/]+)/?$ /searchPage.php?crs_category=$1 [QSA,L,NC]
  
  
  RewriteCond %{THE_REQUEST} /index\.php/(\S+) [NC]
  RewriteRule ^ /page/%1 [NE,R,L]
  RewriteRule ^page/([^/]+)/?$ index.php/$1 [NC,L]
  </code></pre>
  
  <p>Problem:
  For some reason the request doesn't work for these lines:</p>
  
  <pre><code>RewriteCond %{THE_REQUEST} /searchPage.php\?crs_category=([^\s]+) [NC]
  RewriteRule ^category/%1? [NE,NC,R,L]
  </code></pre>
  
  <p>In addition, I am not sure who take into account white space. where if its <code>searchPage.php?crs_category=html%20andcss</code> it leads to category/html and css disregarding the spacing code</p>
  
  <p>Update:</p>
  
  <pre><code>Options +FollowSymlinks -MultiViews
  RewriteEngine on
  RewriteBase /
  
  # keep replacing space to hyphen until there is no space use internal rewrite
  RewriteRule ^([^\s%20]*)[\s%20]+(.*)$ $1-$2 [E=NOSPACE:1]
  
  # when there is no space make an external redirection
  RewriteCond %{ENV:NOSPACE} =1
  RewriteRule ^([^\s%20]+)$ $1 [R=301,L]
  
  RewriteCond %{THE_REQUEST} /searchPage\.php\?crs_category=([^&amp;]+?)\s [NC]
  RewriteRule ^ category/%1? [NE,R,L]
  
  RewriteCond %{THE_REQUEST} /index\.php/(\S+) [NC]
  RewriteRule ^ page/%1 [NE,R,L]
  
  RewriteRule ^category/([^/]+)/?$ searchPage.php?crs_category=$1 [QSA,L,NC]
  
  RewriteRule ^page/([^/]+)/?$ index.php/$1 [NC,L]
  </code></pre>