開発プロジェクトでは、hosts ファイルを使用して実際のドメインを localhost にポイントします。仮想ホストの定義をApache構成ファイルに追加します。私の質問は、すべての「xyz.com」ドメインを「d:/xampp/htdocs/websites/xyz.com」ディレクトリにリダイレクトすることは可能ですか? これにより、毎回 vhost 定義を追加する必要がなくなります。
10189 次
1 に答える
12
VirtualHost
のServerAlias
ディレクティブでワイルドカードを使用できます。
<VirtualHost *:80>
# Official name is example.com
ServerName example.com
# Any subdomain *.example.com also goes here
ServerAlias *.example.com
DocumentRoot "D:/xampp/htdocs/websites/xyz.com"
# Then rewrite subdomains into different directories
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.example.com$
# Use the %1 captured from the HTTP_HOST
# For example abc.example.com writes to websites/abc.com
RewriteRule ^(.*)$ "D:/xampp/htdocs/websites/%1.com/$1" [L]
</VirtualHost>
于 2012-06-23T13:25:09.707 に答える