Nginx: Redirect subdomains to subfolder
<p>I have the following url structure:</p>

<pre><code>domain.com/folder1/folder2/folder3/file.xy
</code></pre>

<p>The folder 1 is always there and what follows is completely flexible and different. For example there could also be:</p>

<pre><code>domain.com/folder1/file.xy
</code></pre>

<p>So basically it is</p>

<pre><code>domain.com/folder1/*
</code></pre>

<p>What I want to achieve now is that I am able to open the subdomain:</p>

<pre><code>folder1.domain.com/*
</code></pre>

<p>with any folder/file at the end and nginx automatically knows that the subdomain is equal to the first subfolder so that the request with the subdomain would be equal to</p>

<pre><code>domain.com/folder1/*
</code></pre>

<p>How am I able to achieve this with nginx?</p>

<p>Thanks for any help!</p>

<p>Edit: Just to clarify it a bit more: the "folder1" can be anything. So basically any subdomain is equal to the first subfolder.</p>