1

我有个问题。

我正在尝试在具有 1 个域的主机上设置 TEST、CERT 和 PROD 网络空间。
问题是我已经在我的网页中使用子域,因此无法配置 DNS 通配符记录。

网址在 PROD 上如下所示:
company1.domain.com company2.domain.com

两者都指向主机上的同一目录。

我要实现的是:
company1.domain.com ->指向目录
company1.test.domain.com1->指向目录
company1.cert.domain.com2->指向目录3

“company1”必须是通配符。此外,我不希望看到 URL 中显示的目录。

任何人都知道如何做到这一点?
我应该删除现有的 DNS 通配符记录吗?

4

1 回答 1

1

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]
于 2012-07-26T20:20:54.403 回答