![](/img/trans.png)
[英]Host Website using IIS 7.5 ,Windows server 2008 R2 and .net framework 4.5
[英]IIS 7.5 WinServer 2008 R2 URL Rewrite Module for multiple domains and multilingual paths
我試圖利用(按標題)IIS URL重寫模塊將一些舊域重定向到新域。 我瀏覽了許多MS Tech文章和各種博客,就我們的情況而言,我認為我對所需的解決方案有所了解,但是,我的重定向未觸發,並且僅收到404錯誤而不是重定向到頁面。
詳細信息:我們目前已經建立了一個多語言站點,例如domain。 com / 英文/路徑/收件人/頁面和域。 de / English / Path / To / Page ,域。 fr / 英文/路徑/到/頁面 。 我們的CMS-Kentico-已設置為可根據頂級域名進行翻譯。 我們現在正在遷移到新站點,並且需要域名。 com / 英文/路徑/收件人/頁面和域。 de / 德語/翻譯/路徑/到/頁面和域。 fr / 法語/翻譯/路徑/到/頁面 。 我相信以下是設置“ rewriteMaps”的正確方法:
<rewrite>
<rewriteMaps>
<rewriteMap name="USRedirects" defaultValue="">
<add key="/OLD/PATH/" value="/NEW/PATH/ENGLISH" />
<add key="/OLD/PATH/" value="/NEW/PATH/ENGLISH" />
<add key="/OLD/PATH/" value="/NEW/PATH/ENGLISH" />
</rewriteMap>
</rewriteMaps>
</rewrite>
<rewrite>
<rewriteMaps>
<rewriteMap name="DERedirects" defaultValue="">
<add key="/OLD/PATH/" value="/NEW/PATH/GERMAN" />
<add key="/OLD/PATH/" value="/NEW/PATH/GERMAN" />
<add key="/OLD/PATH/" value="/NEW/PATH/GERMAN" />
</rewriteMap>
</rewriteMaps>
</rewrite>
注意:“舊路徑”都是相同的,都是英文。 僅域(.de,.com,.fr)表示差異。 展望未來,新網站已翻譯了每種語言的URL。 然后,將以下設置作為我的規則部分:
<rules>
<rule name="US Redirects" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" /> <!-- rule back reference is captured here -->
<conditions>
<add input="{USRedirects:{HTTP_HOST}}" pattern="^www.domain.com$" /> <!-- condition back-reference is captured here -->
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:1}" redirectType="Permanent" /> <!-- rewrite actions uses back-references to condition and to rule when rewriting the URL -->
</rule>
</rules>
<rules>
<rule name="DERedirects" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" /> <!-- rule back reference is captured here -->
<conditions>
<add input="{USRedirects:{HTTP_HOST}}" pattern="^www.domain.de$" /> <!-- condition back-reference is captured here -->
</conditions>
<action type="Redirect" url="http://www.domain.de/{R:1}" redirectType="Permanent" /> <!-- rewrite actions uses back-references to condition and to rule when rewriting the URL -->
</rule>
</rules>
最后,我想要為每種語言/域(DE = domain.de,US = domain.com,FR = domain.fr等)命名的一組規則,其中每個規則都將對應於相應的rewriteMaps(命名為DERedirects,USRedirects,FRRedirects等),使用輸入值{:{HTTP_HOST}}中的引用語法。
歸根結底,這確實沒有崩潰或對我造成了500錯誤,但唯一要做的就是拋出404並說我要重定向的頁面了不存在。
任何幫助將不勝感激。 而且,如果我有其他重要的信息要漏掉,請告訴我,我會盡力提供更多詳細信息。
這是我一直在使用的一些參考:
http://ruslany.net/2010/05/storing-url-rewrite-mappings-in-a-separate-file/
https://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference
http://weblogs.asp.net/owscott/iis-url-rewrite-redirect-multiple-domain-names-to-one
謝謝!
小更新:上面的部分只是整體配置的一部分。 我需要的不只是DE和COM設置。
另外,我嘗試實現的Ruslany文章,但是在設置它時收到了太多500錯誤。 語法或安裝程序無法正常工作,因此我將所有映射和規則直接放入web.config文件中(同時根據要求將其保持在250kb以下)。
找到了我的答案! 只是必須弄清楚/意識到“ {:{HTTP_POST}}”,因為無法進行輸入,所以我可以正確搜索。 找到了這篇文章:
http://forums.iis.net/t/1177509.aspx
並且,如果從互連網上消失,則為復制/粘貼版本:
你好
重寫模塊中的請求URL輸入不包含主機名。 因此,您需要使用{HTTP_HOST}進行驗證。 您可以按照以下說明更新規則以使其起作用:
<rewrite>
<rewriteMaps>
<rewriteMap name="Site1Redirects">
<add key="/mypage" value="/EN/mypage.aspx" />
</rewriteMap>
<rewriteMap name="Site2Redirects">
<add key="/mypage" value="/CY/mypage2.aspx" />
</rewriteMap>
</rewriteMaps>
<globalRules>
<rule name="Redirect rule1 for Site 1" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^site1.mysite.com$" />
<add input="{Site1Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:0}" appendQueryString="false" />
</rule>
<rule name="Redirect rule1 for Site 2" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^site2.mysite.com$" />
<add input="{Site2Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:0}" appendQueryString="false" />
</rule>
</globalRules>
</rewrite>
謝謝。
就這些 ...
更新:僅僅因為我發現這是更有價值的信息:
https://moz.com/blog/what-every-seo-should-know-about-iis#chaining
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.