创建无限的子域,可重定向到PHP中的不同IP
因此,我一直在尝试为我的情况找到适合我的道路,但不能仅仅找到正确的答案。
所以我需要做的是
示例-
我将发布到script.php-?username ='test '& ip ='127.0.0.1'
我需要此发布请求以使用该用户名创建一个子域(该用户名将用于该子域-test.mysite.com
访问test.mysite.com将重定向到127.0.0.1
我试图实现的目标类似于dns服务
是否可以?我需要问问我的房东对于某物(Godaddy / IIS服务器)
谢谢!真的感谢任何潜在客户。
So iv'e been trying to find the right path for me for my situation but couldn't just find the right answer.
So what i need to do is a php script that will create a subdomain that redirects to an IP that will be sent from my post request.
Example -
I post to script.php - ?username='test'&ip='127.0.0.1'
I need this post request to create a subdomain with this username(the username will be used for the subdomain - test.mysite.com
visiting test.mysite.com will redirect to 127.0.0.1
What im trying to achive is something like a dns service.
Is it possible? Do i need to ask my host for something(Godaddy/IIS Server)
Thanks ! Really appreciate any lead.
这需要3步骤:
- 您需要为域的子域创建通配符DNS条目
*。example.com A 192.0.0.10
*.example.com A 192.0.0.10
- 然后您需要为apache服务器设置一个新的虚拟主机条目。如果它与该子域重定向系统在同一台计算机上运行,则应该在现有服务器的虚拟主机条目之后。
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www
ServerName www.example.com
ServerAlias *.example.com
</VirtualHost>
- 最后,您编写索引.php脚本来获取
$ _ SERVER ['HTTP_HOST']
,并以此为基础,在数据库中查找您的子域名,并发送标头('Location: ')基于在数据库中的成功查找。 - Finally, you write your index.php script to get
$_SERVER['HTTP_HOST']
and based on that, to do a lookup in the database for your subdomain name, and send the header('Location:') based on a successful lookup in the database.