title: nginx subdomain and domain rewrite w proxy pass
body: <p>I need these two types of rewrites:</p>
  
  <p><code>subdomain.domain.com =&gt; domain.com/website/subdomain</code></p>
  
  <p><code>otherdomain.com =&gt; domain.com/userdomain/otherdomain.com</code></p>
  
  <p>My problem is that I want the user to see <code>subdomain.domain.com</code>, and <code>otherdomain.com</code>, not the redirected version. My current rewrite in nginx works, but the user's URL shows the rewrite, and I want this to be transparent to the user, any ideas?:</p>
  
  <pre><code>upstream domain_server { server localhost:8000 fail_timeout=0; }     
  
  server {
          listen  80;
          root  /var/www/domain.com;
  
          server_name domain.com ~^(?&lt;subdomain&gt;.*)\.domain\.com$ ~^(?&lt;otherdomain&gt;.*)$;
          if ( $subdomain ) {
                  rewrite ^ http://domain.com/website/$subdomain break;
          }
          if ( $otherdomain ) {
                  rewrite ^ http://domain.com/userdomain/$otherdomain break;
          }
  
          location / {
                  proxy_redirect off;
                  proxy_buffering off;
                  proxy_set_header Host $http_host;
                  proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
                  if (!-f $request_filename) {
                          proxy_pass http://domain_server;
                          break;
                  }
          }
  
  }
  </code></pre>