title: Merge into one rewrite rule: removal of trailing slashes, and www
body: <p>How may I merge the removal of the trailing slash, and the www re-write rules?</p>
  
  <pre><code>RewriteEngine on
  
  # prevent redirect loop on directory
  DirectorySlash Off
  
  # remove the trailing slash
  RewriteRule ^(.*)/$ /$1 [L,R=301]
  
  # remove www. (generic method with HTTPS support)
  RewriteCond %{HTTP_HOST} ^www\.
  RewriteCond %{HTTPS}s ^on(s)|off
  RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www\.)?(.+)$
  RewriteRule ^ %1%3%{REQUEST_URI} [R,L]
  
  # send everything (except existing files) to index.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule . index.php [L]
  </code></pre>
  
  <p>I use to do this, but the removal of www. didn't support https:</p>
  
  <pre><code># removes www. and trailing slash
  RewriteCond %{REQUEST_URI} /$ [OR]
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*?)/?$ http://%1/$1 [R=301,QSA,NC,L]
  </code></pre>