我正在寻找一种在运行 Apache2.2 和 PHP5 的服务器上拥有多级子域的方法。理想情况下,解决方案将使用 Apache 而不是 PHP。
例如:
www.apps.example.com 或者 test.apps.example.com
我以前在商业网站上看到过这个,但没有看到任何关于如何实现它的解决方案。我本质上是想让用户在任何子域之前输入 www,或者只输入没有 www 的子域。所以 x.example.com 和 www.x.example.com 都解析到同一个目录。
我正在运行 CentOS 5.4 和 Ubuntu 8.04、PHP 5.2.10 和 Apache 2.2
谢谢
最佳答案
您可以使用 PHP 语言将条目动态添加到 apache 配置文件中,但请记住您生活在不确定性的边缘
// add this to your httpd.conf
Include extra/httpd-vhosts.conf
// add this to extra/httpd-vhosts.conf
<VirtualHost *:80>
// with www prefix
DocumentRoot /www/example/x
ServerName x.example1.com
ServerAlias www.x.example1.com
</VirtualHost>
<VirtualHost *:80>
// without www prefix
DocumentRoot /www/example/x
ServerName x.example1.com
</VirtualHost>
关于php - 如何使用 apache2 和/或 PHP 创建多级子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4349848/