创建无限的子域,可重定向到PHP中的不同IP [英] Creating unlimited subdomains that redirect to different IP's in PHP

查看:78
本文介绍了创建无限的子域,可重定向到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.
      • 这篇关于创建无限的子域,可重定向到PHP中的不同IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆