Recently i bought another domain, and i have all of them on 1 hosting. My hosting provides me only with htaccess file where are all redirects from subdomains made. The folder structure now looks like this:
\---www
| .htaccess
|
\---domains
+---example.com
+---site.test.net
\---test.example.com
but because there is lot of folders with different domains and subdomains, i would like to make it looks better, so i would like to create rule in htaccess that will redirect them into folders categorized by their root domain (example.com, test.net etc.).
I tried to search it but i couldnt find any answer that will suit my problem. After week of googling i asked ChatGPT (i know, not the best source to ask) and it provided me with this code:
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
RewriteRule .* - [E=DOMAIN:%2]
RewriteCond %{ENV:DOMAIN} !^$
RewriteCond %{REQUEST_URI} !^/domains/
RewriteRule ^(.*)$ /domains/%{ENV:DOMAIN}/%{ENV:DOMAIN}/$1 [L]
I see that its trying to take only the part of the www that is not in this example presented, so its still trying to find folder called "domains/test.example.com/test.example.com".
Is there even any way to do something like that? Because i even searched the list of variables, that could be possibly used in htaccess and none of them included root domain.