如何设置URL重写IIS7上使多个子域重定向到正确的网站? [英] How to set up URL Rewrite on IIS7 so that multiple subdomains redirect to the correct web site?
问题描述
我问了一个<一个href=\"http://stackoverflow.com/questions/4655577/how-to-create-subdomains-for-iis7-programmatically\">$p$pvious问题如何有多个子域在同一地点都指向;我接受那里的答案是使用URL重写。
I asked a previous question about how to have multiple subdomains all pointing at the same site; the answer I accepted there was to use URL Rewrite.
酷。但对我的生活我无法弄清楚URL重写是如何工作的,我认为我是一个比较聪明的家伙。 | - )的问题很多...
Cool. But for the life of me I cannot figure out how URL Rewrite works, and I consider myself a relatively smart guy. |-) Lots of questions...
- 每个客户(而且会有数百,甚至数千)例如获取自己的子域名
customer1.mydomain.com
,cooldude.mydomain.com
等正则表达式是( 。+)\\。MYDOMAIN \\ .COM
,而所有这些的URL应该被重定向到IIS上一个网站,我命名customers.mydomain.com
。我的URL重写发现所有的例子都是有关引用文件,例如mydomain.com/thing.aspx?id=123
修改mydomain.com/thing/123
,这是我' 。米不是真正感兴趣这里有一个线索:你可以在下面的图片中看到,输入栏总是说后'/'URL路径 - 但似乎没有任何办法更改<。 / LI>
- Each customer (and there will be hundreds, if not thousands) gets their own subdomain e.g.
customer1.mydomain.com
,cooldude.mydomain.com
etc. The regex would be(.+)\.mydomain\.com
, and all of these URLs should be redirected to a website on IIS that I've namedcustomers.mydomain.com
. All the examples I've found on URL Rewrite are about referencing documents, e.g.mydomain.com/thing.aspx?id=123
changes tomydomain.com/thing/123
, which I'm not really interested in. Here's a clue: as you can see in the picture below, the "Input" column always says "URL path after '/'" - but there doesn't appear to be any way to change that.
- 我假设重写规则应该在默认的Web站点来放,但是我希望规则重定向到
customers.mydomain.com
网站。你如何强制重定向到一个特定的网站,以这样的方式,我仍然能够看到子域名(它决定了客户现场,我登录)?
- I am assuming that the rewrite rule should be put on the default web site, but I want the rule to redirect to the
customers.mydomain.com
web site. How do you force the redirect to a specific web site, in such a way that I will still be able to see the subdomain name (which determines the customer site I'm logging into)?
推荐答案
我想你想要做的就是这个工作是添加一个输入条件,你重写规则是什么。您可以在 http://learn.iis.net/page.aspx/469/using-rewrite-maps-in-url-rewrite-module/ 。
I think what you want to do to get this to work is add an input condition to your rewrite rule. You can read about it in the "Referencing a rewrite map from rewrite rule" section at http://learn.iis.net/page.aspx/469/using-rewrite-maps-in-url-rewrite-module/.
下面是一个例子,我想会为你工作:
Here's an example I think will work for you:
<rule name="My Rule">
<match url="(.+)?" negate="false" />
<action type="Redirect" url="http://{C:1}.mydomain.com/{R:0}" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.+)\.mydomain\.com" />
</conditions>
</rule>
这篇关于如何设置URL重写IIS7上使多个子域重定向到正确的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!