title: How to redirect a URL in Nginx
body: <p>I need to redirect every <a href="http://test.com" rel="noreferrer">http://test.com</a> request to <a href="http://www.test.com" rel="noreferrer">http://www.test.com</a>. How can this be done.</p>
  <p>In the server block I tried adding</p>
  <pre><code>rewrite ^/(.*) http://www.test.com/$1 permanent;
  </code></pre>
  <p>but in browser it says</p>
  <blockquote>
  <p>The page isn't redirecting properly</p>
  <p>Firefox has detected that the server is redirecting the request for this address in a way that will never complete.</p>
  </blockquote>
  <p>My server block looks like</p>
  <pre><code> server {
              listen       80;
              server_name  test.com;
              client_max_body_size   10M;
              client_body_buffer_size   128k;
  
              root       /home/test/test/public;
              passenger_enabled on;
              rails_env production;
  
              #rewrite ^/(.*) http://www.test.com/$1 permanent;
              #rewrite ^(.*)$ $scheme://www.test.com$1;
  
              error_page   500 502 503 504  /50x.html;
              location = /50x.html {
                      root   html;
              }
      }
  </code></pre>