title: nginx rewrite html file and add trailing slash
body: <p>I have read a dozen rewite questions. Most questions are for .php but I have simple .html files so about => about.html .But I am not able to get nginx to do this:</p>
  
  <ul>
  <li>accept url with or without "/" </li>
  <li>redirect domain.com/about and domain.com/about/ to domain.com/about.html</li>
  <li>add trailing slash to the URL so if I write domain.com/about it writes domain.com/about/</li>
  </ul>
  
  <p>I have tried with this code
  <code>rewrite ^/([a-zA-Z0-9]+)$ /$1.html;</code>
  but it gives me 404 error on url ending with "/". Also tried this 
  <code>rewrite ^([a-zA-Z0-9]+)/?$ $1.html</code> with same error.</p>
  
  <p>Some suggest I should be using try <code>try_files</code>?</p>
  
  <p>I tried this also which gives a 500 error:</p>
  
  <pre><code>location / { 
  rewrite ^(.*)$ /%1 redirect; 
  rewrite ^/([^\.]+)$ /$1.html break; 
  }
  </code></pre>
  
  <p>I tried to convert apache to nginx (winginx.com) from suggestion <a href="https://stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash-from-url?rq=1">here</a> with no success. </p>
  
  <p>This code does not work. I am trying to redirect and add trailing slash:</p>
  
  <pre><code>if (!-e $request_filename){
  rewrite ^/(.*)/$ /$1 redirect;
  }
  if (!-e $request_filename){
  rewrite ^/(.*[^/])$ /$1/ redirect;
  }
  </code></pre>
  
  <p>Any suggestion would make me happy.</p>