title: Redirect wildcard subdomains to subdirectory, without changing URL in address bar
body: <p>I've read a lot of questions and answers about this on here but none that seem to solve my specific problem.</p>
  
  <p>I want to redirect any subdomain to the subdirectory to match.</p>
  
  <p>So: x.domain.com would go to domain.com/x, and y.domain.com would go to domain.com/y - But I want to do this without the URL in the address bar changing.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>    Options +FollowSymLinks 
  
      RewriteEngine on
  
      RewriteBase /
  
      RewriteCond %{HTTP_HOST} !^(www)\. [NC]
  
      RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com [NC]
  
      RewriteRule ^ /%1 [P,L]
  </code></pre>
  
  <p>But this takes me to a website redirect loop, with an incorrect address in the URL bar where the subdomain still exists.</p>
  
  <p>For example, x.domain.com takes me to x.domain.com/x and I get a redirect loop error.</p>
  
  <p>I'd be grateful if anyone can point me in the right direction! Nothing I change seems to work...</p>