So if you have a structure like this:
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
And you want each of the 'subdomain' folders to be visible at http://subdomain1.example.com instead of http://example.com/subdomain1/...
Can you achieve this with a combination of the wildcard subdomain DNS setting and just a .htaccess file?
For instance, I have the wildcard subdomain added via cPanel and I have in my .htaccess file (root of the example.com folder):
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^([^.]+).example.com$ [NC]
RewriteCond %{REQUEST_URI} !%1
RewriteRule ^(.*)$ /%1/$1 [L]
</IfModule>
But every time I try to visit one of the subfolders at the subdomain URL, I get a 500 error.
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?
I can also still visit http://example.com/subdomain1/ and see the site. It doesn't redirect to the subdomain as I thought it would.
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.
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.
///EDIT///
Below is the .htaccess file in the public_html/ root directory. There is no .htaccess in the public_html/folder/ directory.
# ----------------------------------------------------------------------
# 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
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
# mod_headers, y u no match by Content-Type?!
<FilesMatch "\.(gif|png|jpe?g|svg|svgz|ico|webp)$">
SetEnvIf Origin ":" IS_CORS
Header set Access-Control-Allow-Origin "*" env=IS_CORS
</FilesMatch>
</IfModule>
</IfModule>
# ----------------------------------------------------------------------
# Webfont access
# ----------------------------------------------------------------------
# Allow access from all domains for webfonts.
# Alternatively you could only whitelist your
# subdomains like "subdomain.example.com".
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
AddType audio/ogg ogg ogv
AddType video/ogg ogg ogv