title: .htaccess: clean url with smart filters
body: <p>Spent 2 days mixing and matching rules from stackoverflow and other sites but there's no luck, a part will work and the other part will not :( I want something like "smart" rule to filter errors. </p>
  
  <ul>
  <li>example.com/<strong>user/</strong> or example.com/<strong>user</strong> needs to point to same location e.g. example.com/profile.php?viewuser&amp;who=$1 </li>
  </ul>
  
  <p>Problem: In my current setup, it just loop to white screen when theres a trailing slash so i decided to "manually" remove trailing slash. By the way the white screen produced when view-sourced contains the correct html markup - it just was not displayed i dont know why.</p>
  
  <ul>
  <li>example.com/<strong>user</strong>/<em>notexistingurl</em> must throw an error but will retain the url structure of links, to be at the example.com/ level.</li>
  </ul>
  
  <p>Problem: Mine was broken to example.com/<strong>user</strong>/links.php instead of example.com/links.php</p>
  
  <p>By the way <strong><em>user</em></strong> is a variable, so it could take <strong><em>simonsoft</em></strong>, <strong><em>anotheruser</em></strong>, etc. In case you see that theres nothing wrong in my site, its actually fixed when i used <code>&lt;base&gt;</code> tag. removal of that tag makes a mess then. Im looking for someone to provide some corrections on my rules below and possibly to not rely on <code>rewritebase</code> or <code>base</code> tags</p>
  
  <p>Here is my existing .htaccess</p>
  
  <pre><code>Options -MultiViews
  Options +FollowSymlinks
  Options -Indexes
  
  RewriteEngine On
  
  RewriteCond %{ENV:REDIRECT_STATUS} 200
  RewriteRule ^ - [L]
  
  # remove the trailing slash
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R,L]
  
  # Some "static" links
  RewriteRule about$ 22688.html [NC,R,L]
  RewriteRule privacy$ 77.html [NC,R,L]
  RewriteRule terms$ 867.html [NC,R,L]
  RewriteRule login$ index.php [NC,L]
  RewriteRule logout$ logout.php [NC,L]
  RewriteRule register$ register.php?do=regterm [NC,L]
  # Quick login url
  RewriteRule ^([a-zA-Z0-9\-_.]+):([^/]*)$ login.php?do=login&amp;loguid=$1&amp;logpwd=$2 [NC,L]
  
  # The vanity url
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^([a-z0-9\-_.]+)$ profile.php?do=viewuser&amp;who=$1 [NC,QSA,L]
  RewriteRule ^([a-z0-9\-_.]+)/friends$ profile.php?do=friends&amp;who=$1 [NC,QSA,L]
  </code></pre>
  
  <p>Help is appreciated. Thanks!</p>