我试图解决这个问题;
我有一个默认网站,其中包含一个位于子文件夹中的应用程序,例如: /app/app.html
它还接受语言参数,因此例如http://192.168.0.1/app/app.html?language=fi可以使用。
现在我有两个子域,我不仅要将其重写到正确的文件夹,还要包含语言参数。例如:
fi.domain.com - > http://1.1.1.1/app/app.html?language=fi
swe.domain.com - > http://1.1.1.1/app/app.html?language=swe
我已将两个子域的A记录指向1.1.1.1
目前没有特殊绑定(只有端口80,没有主机名和所有IP),也没有特殊的默认页面。
编辑:我尝试过使用网址重写器模块,但我还没有按照预期的方式使用它。编辑2:我的第一个例子是我需要它如何工作有点缺陷,这是一个更好的版本;
finnishword.domain.com - > http://1.1.1.1/app/app.html?language=fi
otherwordinswedish.domain.com - > http://1.1.1.1/app/app.html?language=swe
答案 0 :(得分:1)
我不太清楚你的问题。 您似乎需要URL重写规则。
根据此link
<rule name="CName to URL - Rewrite" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(.*)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language={C:1}" />
</rule>
我认为这就是你所需要的;)
编辑2016年8月24日 如果您不能使用RegEx拥有dynmique模式,则必须执行与子域相同的规则:
<rule name="finnishRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(finnishword)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language=fi" />
</rule>
<rule name="finnishRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(otherwordinswedish)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language=swe" />
</rule>
如果你想在网址上重定向包含“瑞典语”一词的所有子域名,你可以将所有子域名混合在一起吗?
<rule name="finnishRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(.*swedish.*)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language=swe" />
</rule>
毕竟RegEx模式取决于你;)
编辑2016年8月25日
也许您必须添加条件才能跳过静态文件
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
...
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
答案 1 :(得分:0)
<rules>
<clear />
<rule name="swedishMainRule" enabled="true" stopProcessing="true">
<match url="^$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?swedishword\.domain\.fi$" />
<add input="{QUERY_STRING}" pattern="language=" negate="true" />
</conditions>
<action type="Redirect" url="?language=sve" appendQueryString="false" logRewrittenUrl="false" />
</rule>
<rule name="swedishRule" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?swedishword\.domain\.fi$" />
</conditions>
<action type="Rewrite" url="/app/{R:1}" />
</rule>
<rule name="finnishRule" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?anotherfinnishword\.domain\.fi$" />
</conditions>
<action type="Rewrite" url="/app/{R:1}" />
</rule>
</rules>
这就是我最终做到这一点的方式,基本上是第一个规则处理语言参数,其他规则只是重写URL。芬兰规则不需要额外的语言规则,因为该应用程序的默认语言是芬兰语。