title: Nginx Sub-Domain+Folder to Domain+URI Redirect
body: <p>I'm trying to redirect old sub-domain with folder to new domain without that old folder but including the uri. Perhaps there is a way to remove "/tv/" part on new redirected url.</p>
  
  <p>OLD URL:</p>
  
  <pre><code>http://demo.domain.com/tv/page1/id1
  </code></pre>
  
  <p>NEW URL (WANTED):</p>
  
  <pre><code>http://http://domain.com/page1/id1
  </code></pre>
  
  <p>Now this rule is what I have so far and it kind of works:</p>
  
  <pre><code>server {
    listen ip:port;
    server_name demo.domain.com;
    return 301 http://domain.com$request_uri;
  }
  </code></pre>
  
  <p>This redirects to:</p>
  
  <pre><code>http://domain.com/tv/page1/id1
  </code></pre>
  
  <p>and I need to remove that "tv" part from url, and have it redirect to:</p>
  
  <pre><code>http://domain.com/page1/id1
  </code></pre>
  
  <p>But at same time I need to have 301 redirect that is good for SEO.</p>
  
  <p>If you have any ideas, please let me know. Thank you.</p>