title: htaccess get domain name from %{HTTP_HOST} into variable, minus the www
body: <p>I currently have the following in a htaccess file which redirects certain requests to the requested domain's individual folder if the file does not exist in the root..</p>
  
  <pre><code>RewriteRule ^contact/?$ ASSETS/%{HTTP_HOST}/contact.php
  
  RewriteCond %{REQUEST_URI} !^/ASSETS/%{HTTP_HOST}/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ /ASSETS/%{HTTP_HOST}/$1
  RewriteCond %{HTTP_HOST} ^(www.)?%{HTTP_HOST}$
  RewriteRule ^(/)?$ ASSETS/%{HTTP_HOST}/index.php [L]
  </code></pre>
  
  <p>Which works fine when my domain folders are named like /ASSETS/www.domain1.com, /ASSETS/www.domain2.com etc</p>
  
  <p>However, I've built a lot of my code already with the assumption that the folders will be labeled /ASSETS/domain1.com etc (domain name, minus the www.)</p>
  
  <p>I'm thinking there is a way to get the domain name from %{HTTP_HOST} into a new variable and strip out the www. part (like an str_replace or something), but all the answers I have found are around a basic redirect all to www. or no www. which isn't going to work as I still want users to access the site from the forced www. version.</p>
  
  <p>I was previously running the rules for each domain individually with a RewriteCond %{HTTP_HOST} ^(www.)?domain1.com$ but there are so many domains now, it's not feasible to do it for each one.</p>
  
  <p>Hope you can help! Thanks in advance.</p>