通配符子域 [英] Wildcard Subdomains

查看:127
本文介绍了通配符子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道以前有一些线程,但是我已经尝试了所有建议的内容(我可以找到),到目前为止,对我来说没有任何作用...

I know there have been a few threads on this before, but I have tried absolutely everything suggested (that I could find) and nothing has worked for me thus far...

考虑到这一点,这是我要尝试做的事情:

With that in mind, here is what I'm trying to do:

首先,我想允许用户发布页面并为他们提供各自选择的子域(例如:user.mysite.com).据我所知,最好的方法是使用mod_rewrite和.htaccess将user.mysite.com映射到mysite.com/user-正确吗?

First, I want to allow users to publish pages and give them each a subdomain of their choice (ex: user.mysite.com). From what I can gather, the best way to do this is to map user.mysite.com to mysite.com/user with mod_rewrite and .htaccess - is that correct?

如果是正确的话,有人可以给我明确的指示以了解如何执行此操作吗?

If that is correct, can somebody give me explicit instructions on how to do this?

此外,我正在使用MAMP在本地进行所有开发,因此,如果有人可以告诉我如何设置本地环境以相同的方式工作(我已经读过这比较困难),那我将欣赏它.老实说,我一直在尝试一切都无济于事,并且由于这是我第一次这样做,所以我完全迷失了.非常感谢您的帮助!

Also, I am doing all of my development locally, using MAMP, so if somebody could tell me how to set up my local environment to work in the same manner (I've read this is more difficult), I would greatly appreciate it. Honestly, I have been trying a everything to no avail, and since this is my first time doing something like this, I am completely lost. Thanks so much for any help!

更新:其中一些答案确实很有帮助,但是对于我所考虑的系统而言,为每个用户手动添加子域不是一种选择.我真正要问的是如何即时执行此操作,并将wildcard.mysite.com重定向到mysite.com/wildcard - Tumblr的设置方式是我想做的一个完美示例.再次感谢!

推荐答案

关于如何设置DNS子域通配符,这将是您的DNS托管提供商的功能.这将是不同的步骤,具体取决于您拥有的托管服务提供商,这对他们来说是一个更好的问题.

As far as how to set up the DNS subdomain wildcard, that would be a function of your DNS hosting provider. This would be different steps depending on which hosting provider you have and would be a better question for them.

使用DNS主机设置好之后,从您的Web应用程序开始,您实际上只是URL重写,这可以通过Web服务器本身的某种模块来完成,例如使用isapi rewrite. IIS(如果可能,这是首选的路由).您还可以在应用程序级别处理重写(例如,如果在ASP.NET上使用路由).

Once you've set that up with the DNS host, from your web app you really are just URL rewriting, which can be done with some sort of module for the web server itself, such as isapi rewrite if you're on IIS (this would be the prefered route if possible). You could also handle rewriting at the application level as well (like using routing if on ASP.NET).

您将重写URL,以便 http://myname.domain.com 变为 http://domain.com/something.aspx?name=myname 或其他名称.从那里开始,您就可以像处理myname值一样正常地处理它了.那有意义吗?希望我不会误会你的追求.

You'd rewrite the URL so http://myname.domain.com would become http://domain.com/something.aspx?name=myname or something. From there on out, you just handle it as if the myname value was in the query string as normal. Does that make sense? Hope I didn't misunderstand what you're after.

我不建议您为每个用户创建一个子域,而是为域本身创建一个通配符子域,因此 anything .domain.com(基本上是* .domain.com)转到您的网站.我使用 mydomain 设置了多个域.他们的设置说明如下:

I am not suggesting that you create a subdomain for each user, but instead create a wildcard subdomain for the domain itself, so anything.domain.com (basically *.domain.com) goes to your site. I have several domains setup with mydomain. Their instructions for setting this up is like this:

是的,您可以配置通配符,但是 只有将其设置为 一个记录.通配符不起作用 带有C名称.要使用通配符,您 使用星号字符"*".为了 例如,如果您创建一个A Record 使用通配符 .domain.com, 在该位置输入的任何内容 ''所在的位置,将解析 到指定的IP地址.所以如果你 输入"www","ftp","site"或 域名之前的任何其他内容, 它将始终解析为IP 地址

Yes, you can configure a wild card but it will only work if you set it up as an A Record. Wildcards do not work with a C Name. To use a wildcard, you use the astericks character '*'. For example, if you create and A Record using a wild card, .domain.com, anything that is entered in the place where the '' is located, will resolve to the specified IP address. So if you enter 'www', 'ftp', 'site', or anything else before the domain name, it will always resolve to the IP address

我通过这种方式进行了一些设置,*.domain.com进入了我的网站.然后,我可以在Web应用程序中阅读基本URL,以查看ryan.domain.com是当前访问的内容,或bill.domain.com是所使用的内容.然后,我可以:

I have some that are setup in just this way, having *.domain.com go to my site. I then can read the base URL in my web app to see that ryan.domain.com is what was currently accessed, or that bill.domain.com is what was used. I can then either:

  1. 使用URL重写,以便子域成为查询字符串OR的一部分
  2. 仅从访问的URL中读取主机值,然后根据该值执行一些逻辑.

这有意义吗?我以这种确切的方式设置了几个站点:使用DNS主机为域创建通配符,然后简单地读取主机或URL中的基础域,以决定基于子域显示的内容(实际上是用户名) )

Does that make sense? I have several sites set up in just this exact way: create the wildcard for the domain with the DNS host and then simply read the host, or base domain from the URL to decide what to display based on the subdomain (which was actually a username)

没有DNS条目将无法执行此操作. 在线世界"需要知道name1.domain.com,name2.domain.com,...,nameN.domain.com都进入服务器的IP地址.唯一的方法是使用适当的DNS条目.您必须使用DNS主机为您的域添加通配符DNS条目.然后,您只需从URL中读取子域并在代码中采取适当的措施即可.

There is no way to do this without a DNS entry. The "online world" needs to know that name1.domain.com, name2.domain.com,...,nameN.domain.com all go to the IP address for your server. The only way to do this is with the appropriate DNS entry. You have to add the wildcard DNS entry for your domain with your DNS host. Then it's just a matter of you reading the subdomain from the URL and taking the appropriate action in your code.

这篇关于通配符子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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