title: Can you make all subfolders subdomains using rewrite rules?
body: <p>So if you have a structure like this:</p>
  
  <pre><code>public_html/folder/example.com/index.php
  public_html/folder/example.com/subdomain1/index.php
  public_html/folder/example.com/subdomain2/index.php
  public_html/folder/example.com/subdomain3/index.php
  </code></pre>
  
  <p>And you want each of the 'subdomain' folders to be visible at <a href="http://subdomain1.example.com" rel="nofollow noreferrer">http://subdomain1.example.com</a> instead of <a href="http://example.com/subdomain1/" rel="nofollow noreferrer">http://example.com/subdomain1/</a>...</p>
  
  <p>Can you achieve this with a combination of the wildcard subdomain DNS setting and just a .htaccess file?</p>
  
  <p>For instance, I have the wildcard subdomain added via <a href="https://en.wikipedia.org/wiki/CPanel" rel="nofollow noreferrer">cPanel</a> and I have in my .htaccess file (root of the example.com folder):</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteCond %{HTTP_HOST} ^([^.]+).example.com$ [NC]
  RewriteCond %{REQUEST_URI} !%1
  RewriteRule ^(.*)$ /%1/$1 [L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>But every time I try to visit one of the subfolders at the subdomain URL, I get a 500 error.</p>
  
  <p>Is there something I'm missing? I've used a .htaccess test tool to make sure the rules were correct. I know mod_rewrite is enabled, and the Apache settings are correct. Is there an issue with the index.php piece of this for instance?</p>
  
  <p>I can also still visit <a href="http://example.com/subdomain1/" rel="nofollow noreferrer">http://example.com/subdomain1/</a> and see the site. It doesn't redirect to the subdomain as I thought it would.</p>
  
  <p>Any help in the right direction would be appreciated. I've been searching and testing different rules for a few hours at this point. I did reach out to my host and verify I had all the appropriate permissions and settings.</p>
  
  <p>If I missed it - the idea here is that whenever a subfolder is added (unless a specific exception is made), it should be accessible as a subdomain address automatically - no manual subdomain add in cPanel / DNS.</p>
  
  <p>///<strong><em>EDIT</em></strong>///</p>
  
  <p>Below is the .htaccess file in the public_html/ root directory. There is no .htaccess in the public_html/folder/ directory. </p>
  
  <pre><code># ----------------------------------------------------------------------
  # CORS-enabled images (@crossorigin)
  # ----------------------------------------------------------------------
  # Send CORS headers if browsers request them; enabled by default for images.
  # developer.mozilla.org/en/CORS_Enabled_Image
  # blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html
  # hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/
  # wiki.mozilla.org/Security/Reviews/crossoriginAttribute
  &lt;IfModule mod_setenvif.c&gt;
    &lt;IfModule mod_headers.c&gt;
      # mod_headers, y u no match by Content-Type?!
      &lt;FilesMatch "\.(gif|png|jpe?g|svg|svgz|ico|webp)$"&gt;
        SetEnvIf Origin ":" IS_CORS
        Header set Access-Control-Allow-Origin "*" env=IS_CORS
      &lt;/FilesMatch&gt;
    &lt;/IfModule&gt;
  &lt;/IfModule&gt;
  # ----------------------------------------------------------------------
  # Webfont access
  # ----------------------------------------------------------------------
  # Allow access from all domains for webfonts.
  # Alternatively you could only whitelist your
  # subdomains like "subdomain.example.com".
  &lt;IfModule mod_headers.c&gt;
    &lt;FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$"&gt;
      Header set Access-Control-Allow-Origin "*"
    &lt;/FilesMatch&gt;
  &lt;/IfModule&gt;
  
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  
  AddType audio/ogg ogg ogv
  AddType video/ogg ogg ogv
  </code></pre>