title: MOD_REWRITE for URL variables, removing empty parameters and using more than 1field for the first and second variables
body: <p>I have a previous question that was answered very well but requires an amendment and I was unable to reply so have created a new question.</p>
  
  <p>I required a mod_rewrite that made the following:</p>
  
  <pre><code>www.example.com?page=var1&amp;cat=var2&amp;subcat=var3&amp;subsubcat=var4
  </code></pre>
  
  <p>into this:</p>
  
  <pre><code>www.example.com/var1/var2/var3/var4/
  </code></pre>
  
  <p>but that also covered the optional use of var2, var3 and var4 so if those variables were empty, it would still work.</p>
  
  <p>The question was answered very well but it requires an amendment to work with different field options for var2, var3 and var4.</p>
  
  <p>The code I have is:</p>
  
  <pre><code>RewriteEngine on
  Options +FollowSymlinks -MultiViews
  
  RewriteCond  %{QUERY_STRING} !^page= [NC]
  RewriteRule ^([^/]+)/?$ /?page=$1 [L]
  
  RewriteCond  %{QUERY_STRING} !^page= [NC]
  RewriteRule ^([^/]+)/([^/]*)/?$ /?page=$1&amp;cat=$2 [L]
  
  RewriteCond  %{QUERY_STRING} !^page= [NC]
  RewriteRule ^([^/]+)/([^/]*)/([^/]*)/?$ /?page=$1&amp;cat=$2&amp;subcat=$3 [L]
  
  RewriteCond  %{QUERY_STRING} !^page= [NC]
  RewriteRule ^([^/]+)/([^/]*)/([^/]*)/([^/]*)/?$ /?page=$1&amp;cat=$2&amp;subcat=$3&amp;subsubcat=$4 [L]
  </code></pre>
  
  <p>This works but I need it to be able to make an if-or-else for the choice of what field is being used for what variable and to tell the difference.</p>
  
  <p>For example, if we have the following two strings normally, it is easy to distinguish what field goes for what variable:</p>
  
  <pre><code>www.example.com?page=var1&amp;cat=var2&amp;subcat=var3&amp;subsubcat=var4
  
  www.example.com?othervar1=var1&amp;othervar2=var2&amp;othervar3=var3&amp;othervar4=var4
  </code></pre>
  
  <p>but for this string, it requires the ability to distinguish what field the variable is for:</p>
  
  <pre><code>www.example.com/var1/var2/var3/var4/
  </code></pre>
  
  <p>I need the mod_rewrite to choose which is being used.</p>
  
  <p>As well as this, when I actually go to a folder that does exist, it does work correctly. For example, if I go to a folder called "test", which is an actual folder:</p>
  
  <pre><code>www.example.com/test/
  </code></pre>
  
  <p>it uses it as a variable for the "page" field. If I use the following without the end forward slash:</p>
  
  <pre><code>www.example.com/test 
  </code></pre>
  
  <p>it outputs the following into the URL:</p>
  
  <pre><code>www.example.com/test/?page=test
  </code></pre>
  
  <p>I need it to work for folders that exist as normal also.</p>
  
  <p>Please can someone tell me how this can be done? I would appreciate any help in resolving this issue.</p>
  
  <p>Also, can someone tell me what the "-MultiViews" bit means at the beginning as I have not come across this before?</p>
  
  <p>Thank you.</p>