Nginx rewrite requests to subdomain.tld/files/* to external domain
<p>I'd like to rewrite all requests to Nginx matching <code>http://*.examle.tld/files/*</code> to <code>http://$1.otherdomain.tld/files/?file=$2</code>. I'd also like to rewrite the same request without the subdomain i.e. <code>http://example.tld/files/*</code> to <code>http://otherdomain.tld/files/?file=$1</code></p>

<p>The reason for this is to use production files from local development without having to sync folders.</p>

<p>This is what I've got so far, however without success:</p>

<pre><code>location / {
    ...
    rewrite ^http://(\w+)\.(.*)/files/(.*) http://$1.otherdomain.tld/inc/reader.php?file=$3;
    rewrite ^.*/files/(.*) http://$1.otherdomain.tld/inc/reader.php?file=$1;
    ...
}
</code></pre>

<p>Thank you for any assistance. </p>