I am trying to create an .htaccess file that will change the document root of a domain to a subfolder on my server without actually changing the url to the end user. Here is an example of what I am trying to do:
domain1.com
will look for web content in/domains/domain1.com
but still appear asdomain1.com
.domain2.com
will look for web content in/domains/domain2.com
but still appear asdomain2.com
.
Every domain will be pointed to the root directory /
so I am placing the .htaccess file here, /.htaccess
.
I do not want to have to add every domain I have to the .htaccess file, I would like it to follow this format for every domain that comes its way.
I tried learning about .htaccess and create one myself, however, I can't seem a way to this. What I have currently have makes each domain redirect to its subdirectory and gives an error of "too many redirects".
- ie.
domain1.com
redirects the end user todomain1.com/domains/domain1.com
This is the contents of the .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^(.*)$ /domains/%1 [L]