靜態內容域的 IIS 重定向規則 (IIS redirect rules for static content domains)


問題描述

靜態內容域的 IIS 重定向規則 (IIS redirect rules for static content domains)

I've written some rules for our static content subdomains so that, when they come into IIS, they are redirected to our www. subdomain.

The reason for this is that we have several subdomains being indexed by Google. However, when I create the urls, I am still able to view files at img1.mydomain.com with the statuscode being 200, rather than 301 as I would expect.

Am I doing something wrong?

<!-- Force img domains and non-www users to point at www. -->
<rule name="redirectImgJsAndNonWww" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^img1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img3.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js3.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^mydomain.com$" />
  </conditions>
  <action type="Redirect" url="www.mydomain.com/{R:0}" redirectType="Permanent" />
</rule>

Many thanks for any help.

Update: It appears that I was missing the logicalGrouping flag, which was setting my rules to "MatchAll".

<rule name="Redirect to WWW" stopProcessing="true">
  <match url=".*" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img3.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js3.mydomain.com$" />
  </conditions>
  <action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" />
</rule>

參考解法

方法 1:

The question has now been answered.

It appears that I was missing the logicalGrouping flag, which was setting my rules to "MatchAll".

<rule name="Redirect to WWW" stopProcessing="true">
  <match url=".*" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^img3.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js1.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js2.mydomain.com$" />
    <add input="{HTTP_HOST}" pattern="^js3.mydomain.com$" />
  </conditions>
  <action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" />
</rule>

(by Dan AtkinsonDan Atkinson)

參考文件

  1. IIS redirect rules for static content domains (CC BY-SA 3.0/4.0)

#ASP.NET #url-rewriting #iis-7






相關問題

System.Reflection.Assembly.LoadFile 鎖定文件 (System.Reflection.Assembly.LoadFile Locks File)

如何在沒有全局變量的情況下一直保留我的變量? (How can I keep my variable all the time without global variables?)

C# / ASP.NET - Web 應用程序鎖定 (C# / ASP.NET - Web Application locking)

關閉模態對話框窗口後 ASP.NET 刷新父頁面 (ASP.NET Refresh Parent Page after Closing Modal Dialog Window)

無法將 NULL 值傳遞給數據庫 (Unable to pass NULL value to database)

wcf:將用戶名添加到消息頭是否安全? (wcf: adding username to the message header is this secure?)

使用 ASP.Net 教初學者 Web 開發的小項目想法 (Small projects ideas to teach beginners web development using ASP.Net)

SQL Server - 分組、擁有和計數 (SQL Server - Group by, having and count in a mix)

企業庫異常處理應用程序塊和日誌記錄應用程序塊在 ASP.NET 中的正確使用 (Enterprise Library Exception Handling Application Block and Logging Application Block proper use in ASP.NET)

來自proc的asp.net多個結果集:是否有必要將結果映射到類?如果是這樣,怎麼做? (asp.net multiple result set from proc: is it necessary to map results to class? If so, how?)

如何在測試工具中實例化 asp.net 代碼隱藏類? (How can I instantiate an asp.net codebehind class in a test harness?)

Web 窗體用戶控制事件,需要在頁面加載後添加 (Web Form User Control Event, needs to be added after page loads)







留言討論