问题描述
我正在尝试托管一个网站,该网站的用户个人资料页面带有唯一的子域,例如username.sitename.com。我想要一个Apache / VirtualHost解决方案,用于将* .sitename.com指向sitename.com/index.php,我可以在其中进行分类,哪个子域带有配置文件页面,并且显示404错误。
I'm trying to host a site on which user profile pages come with unique subdomains, such as username.sitename.com. I would like an Apache/VirtualHost solution for pointing *.sitename.com to sitename.com/index.php, where I could assort, which subdomain comes with a profile page and which would show 404 error.
请帮助我设置.htaccess
Please help me setting up the .htaccess
推荐答案
您只需要正确的VirtualHost设置即可。
You need only a correct VirtualHost setup.
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
[...]
</VirtualHost>
由于index.php位于DirectoryIndex中,因此无论调用哪个域,它都会被自动调用。通过变量 $ _ SERVER ['HTTP_HOST']
对请求的主机进行动态响应。
As the index.php is in the DirectoryIndex it is called automatically, regardless which domain is called. Do dynamically react you have acces to the requested host trough the $_SERVER['HTTP_HOST']
variable.
这篇关于如何将所有子域指向index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!