2016-08-22 79 views
0

我試圖圍繞這個問題來解決我的問題;將子域名重寫爲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

回答

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> 

我認爲這是你需要的;)

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

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> 

這就是我最終這樣做的基本上第一條規則處理w使用language參數,其他規則只是重寫URL。芬蘭規則不需要額外的語言規則,因爲該應用的默認語言是芬蘭語。