我可以使用 GoDaddy 托管动态创建子域(PHP、.htaccess)吗?
我正在尝试结合使用 .htaccess 和 PHP 在我的 GoDaddy 托管帐户上动态创建子域。我在尝试使用通配符星号修改区域时遇到了问题。我根本不熟悉它是如何工作的,并且只是通过广泛探索域管理器找到了有关该域的区域内容。我不确定我是否知道自己在做什么。我对 .htaccess 稍微熟悉一些,尽管编写 RegEx 对我来说仍然是一个很大的挑战。
我研究了另一个教程,该教程将使用 .htaccess 将子域重新路由到我的域根目录中的文件夹(例如 sub.domain.com 到domain.com/sub)。这是我的代码:
#Grab the subdomain from the domain
RewriteCond %{HTTP_HOST} ^([^.]+).MY-DOMAIN.com$
#Make sure the subdomain is not www or example
RewriteCond %{1} !^(www)$
#Check if the directory actually exists before we go there
RewriteCond /home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/%1 -d
#This stops it from looping
RewriteCond %{REQUEST_FILENAME} !^/home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/
#Finally, this is the actual rewrite
RewriteRule (.*) /home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/%1 [L]
截至目前,我已完成以下操作:
- 登录 GoDaddy 域名管理器。
- 转到工具> DNS 管理器。
- 打开我的域的区域文件编辑器。
- 添加了带有主机名 * 的 A(主机)记录,并在指向 IP 地址中我复制了 @ 条目的 IP 地址中的值,因为它应该与我的域相同...?
- 现在,等到名称服务器或任何更新和传播之类的内容之后,当我尝试访问子域时,我收到 403 错误。
有什么建议吗?
I am trying to use a combination of .htaccess and PHP to create subdomains on-the-fly on my GoDaddy Hosting account. I've run into a problem of trying to modify the zone using the wildcard asterisk. I am not at all familiar with how this works and have only found the zone stuff about the domain by exploring the domain manager extensively. I'm not sure I know what I'm doing. I'm slightly more acquainted with .htaccess, although it's still a big challenge for me to write RegEx.
I've researched another tutorial that will use .htaccess to reroute a subdomain to a folder in the root of my domain (e.g. sub.domain.com to domain.com/sub). Here's my code:
#Grab the subdomain from the domain
RewriteCond %{HTTP_HOST} ^([^.]+).MY-DOMAIN.com$
#Make sure the subdomain is not www or example
RewriteCond %{1} !^(www)$
#Check if the directory actually exists before we go there
RewriteCond /home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/%1 -d
#This stops it from looping
RewriteCond %{REQUEST_FILENAME} !^/home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/
#Finally, this is the actual rewrite
RewriteRule (.*) /home/content/X/Y/Z/XYZ-MY-GODADDY-ACCT/html/%1 [L]
As of right now, I've done the following:
- Logged into GoDaddy Domain Manager.
- Went to Tools > DNS Manager.
- Opened the Zone File Editor for my domain.
- Added an A (Host) Record with Host Name * and in Points to IP Address I copied the value from the @ entry's IP address, since that should be the same as my domain...?
- Now, after waiting until the nameservers or whatever updated and propogated and stuff, I get a 403 error when I try to access a subdomain.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DNS 只是配置的 1 部分。您需要在 Apache 中的虚拟主机配置中为 *.mydomain.com 设置一个 ServerAlias,否则 Apache 将不知道将 *.mydomain.com 的请求路由到哪里 - 这意味着 .htaccess 永远没有机会根本不工作。
如果 GoDaddy 提供了一种手动编辑虚拟主机指令的方法,或者至少能够通过其 GUI 添加服务器别名,那么这很简单。如果您找不到它,您应该联系 GoDaddy 获取信息。
DNS is only 1 part of the configuration. You need to have a ServerAlias for *.mydomain.com in the configuration for the virtual host in Apache, otherwise Apache will not have any idea where to route requests for *.mydomain.com - which means the .htaccess never has a chance to work at all.
If GoDaddy provides a way to manually edit your virtual hosts' directives, or at least the ability to add server aliases through their GUI, then it's easy enough. If you can't find it, you should contact GoDaddy for information.
建议我将答案从 这里回答这个问题:
虽然与为每个动态添加的子域创建新的虚拟主机条目不同,但您应该能够使用通配符 DNS 记录进行设置并向您的托管帐户添加专用 IP 。您可以使用以下方法将专用 IP 添加到您的托管帐户:
注意:专用 IP 可能需要 24 小时才能在您的托管帐户上激活。
您可以在我们的 DNS 管理器中设置 *.yourdomain.com 以使用您的共享托管帐户的专用 IP。
I was advised to move my answer from here to this question:
While not the same as being able to create a new vhost entry for each subdomain dynamically added, you should be able to set this up using a Wildcard DNS record and adding a dedicated IP to your hosting account. You can add a dedicated IP to your hosting account using this method:
NOTE: Dedicated IPs can take 24 hours to become active on your hosting account.
You can setup *.yourdomain.com to use the dedicated IP of your shared hosting account in our DNS Manager.
我刚刚与 GoDaddy 技术支持通了电话,得到了一个出色的解决方案,不需要使用 mod_rewrite 或升级到专用服务器。
从您的帐户登录 https://gateway.godaddy.com 从下拉列表中选择“托管”,然后在页面上选择“托管”打开,选择设置。在打开的模式窗口中,单击“更改域”按钮并输入虚拟域(请注意,虚拟域不需要在 DNS 中注册或输入。然后,这会将您的默认域更改为虚拟域,该虚拟域将驻留在 。
完成此操作后,转到 cPanel 并从顶部的绿色菜单栏中选择 Addon Domains,输入新域并输入您注册的域的名称,然后指定文档根 (DocRoot) 路径 可以是完全位于 public_html 文件夹之外的目录位置,以便您可以创建一个 Laravel 友好路径,例如 webroot/mydomain.com/public 并在 webroot/mydomain.com 中安装 Laravel。
同样,您可以为子域指定类似的路径
希望这对每个人都有帮助。看着这个。
I just got off the phone with GoDaddy tech support, and was given a brilliant solution that doesn't require using mod_rewrite or upgrading to a dedicated server.
From your account login at https://gateway.godaddy.com select Hosting from the dropdown and then on the page that opens, select Settings. In the modal window that opens, click the Change Domain button and enter in a dummy domain (note the dummy domain does not need to be registered or entered in DNS. This will then change your default domain to the dummy domain which will reside in the public_html folder.
After you have done that, go to the cPanel and choose Addon Domains from the green menu bar at the top. Enter a new domain and type the name of your registered domain, then specify the document root (DocRoot). The path can be a directory location completely outside of the public_html folder so you can create a Laravel friendly path such as webroot/mydomain.com/public and install Laravel in webroot/mydomain.com.
Likewise, you can specify similar paths for subdomains.
Hope this helps everyone looking at this.