将子域名重写为IIS中的子文件夹和参数

问题描述:

我试图围绕这个问题来解决我的问题;将子域名重写为IIS中的子文件夹和参数

我有一个默认站点,其中有一个应用程序驻留在子文件夹中,例如, /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

我做了一个记录两个子域名指向1.1.1.1

目前没有特殊的绑定(只有端口80,没有主机名和所有IP),也没有特殊的默认页面。

编辑:我试过使用URL重写器模块,但我一直无法按预期工作。

编辑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

您是否尝试过ARR中的UrlRewrite模块和/或重写规则?你没有描述你目前的做法,这可能意味着你错过了这两个明显的可能性。 –

+0

对不起,忘了补充一点,看我的编辑! – Stuggi

我不知道要很好的理解你的问题。 看来你需要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> 

我认为这是你需要的;)

编辑24/08/2016 如果你不能有一个正则表达式模式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> 

或者你可以混合在一起,如果你想重新直接在url上包含单词“swedish”的所有子域名?

<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> 

因此,所有的正则表达式模式后是给你;)

编辑25/08/2016

也许你需要添加条件跳过静态文件

<conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
... 
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
</conditions> 
+0

是的,谢谢,我会尝试并报告回来,我没有那么多重写规则的经验,所以我必须以某种方式向后做! – Stuggi

+0

嗯,我现在看到该如何工作,但我也注意到我的例子有点有缺陷。该子域与我的示例中的语言参数不匹配,请参阅我的第二次编辑以获取更准确的示例。 – Stuggi

+1

只需更改模式就可以做到这一点,因此您必须执行多个规则,每个子域一个规则。我很快就会编辑答案 – Mathieu

<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> 

这就是我最终这样做的基本上第一条规则处理w使用language参数,其他规则只是重写URL。芬兰规则不需要额外的语言规则,因为该应用的默认语言是芬兰语。