title: How to avoid chain redirections using mod_rewrite?
body: <p>Basicly i'm working on my site to be SEO-friendly. I wanted to achieve following:</p>
  
  <ul>
  <li>Rewrite urls to pretty ones</li>
  <li>Remove multiple slashes (eg. <code>example.com/////something///</code> to <code>example.com/something/</code></li>
  <li>Redirect www version to a non-www version.</li>
  <li>Hide index.php file from all urls</li>
  <li>Redirect from old (<code>/?id=something/</code> to new urls <code>/something/</code>) </li>
  </ul>
  
  <p>I came up with this <code>.htaccess</code> code:</p>
  
  <pre><code>RewriteCond %{THE_REQUEST} //
  RewriteRule .* $0 [R=301]
  
  RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
  RewriteCond %{QUERY_STRING} ^id=([a-z0-9\/-]+)
  RewriteRule ^(.*)$ http://example.com/%1? [R=301]
  
  RewriteRule ^index.php(.*)$ /$1 [R=301]
  RewriteRule ^([a-z0-9\/-]+)$ /?id=$1 [L] 
  </code></pre>
  
  <p>...and though it's working it has a side effect: chain redirects, eg. <code>example.com/?id=something//////</code> -> <code>example.com/something//////</code> -> <code>example.com/something/</code></p>
  
  <p>So is there a way to rewrite or modify this code so it'll be redirecting just once to the preferred version of the url?</p>