Reputation: 23
I have a question.
I am trying to setup a TEST, CERT and PROD webspace on my hosting with 1 domain.
The problem is that I am already using subdomains in my webpage so DNS wildcard record configuration is not possible.
The url looks as following on PROD:
company1.domain.com
or company2.domain.com
Both pointing to the same directory on the hosting.
What I want to achieve is:
company1.domain.com
-> points to directory1
company1.test.domain.com
-> points to directory2
company1.cert.domain.com
-> points to directory3
"company1" must be a wildcard. Additionally I would not like to see the directory being displayed in the URL.
Anyone has an idea on how to accomplish this?
Should I remove existing DNS wildcard records?
Upvotes: 1
Views: 518
Reputation: 143886
Ideally, you should be making each of these subdomains into a separate vhost and point each vhost to its own directory. Some hosting companies even allow you to assign subdomains to separate directories.
But if for some reason, they all need to point to the same document root, try adding these rules to the htaccess file in the document root:
RewriteEngine On
# for company1
RewriteCond %{HTTP_HOST} company1.domain.com [NC]
RewriteCond %{REQUEST_URI} !^/directory1
RewriteRule ^(.*)$ /directory1/$1 [L]
# for company1.test
RewriteCond %{HTTP_HOST} company1.test.domain.com [NC]
RewriteCond %{REQUEST_URI} !^/directory2
RewriteRule ^(.*)$ /directory2/$1 [L]
# for company1.cert
RewriteCond %{HTTP_HOST} company1.cert.domain.com [NC]
RewriteCond %{REQUEST_URI} !^/directory3
RewriteRule ^(.*)$ /directory3/$1 [L]
Upvotes: 1