【问题标题】:IIS 7.5 WinServer 2008 R2 URL Rewrite Module for multiple domains and multilingual paths用于多个域和多语言路径的 IIS 7.5 WinServer 2008 R2 URL 重写模块
【发布时间】:2016-02-16 06:55:36
【问题描述】:

我正在尝试使用(根据标题)IIS URL 重写模块将一些旧域重定向到新域。我浏览了很多 MS Tech 文章和各种博客,对于我们的情况,我想我知道所需的解决方案,但是,我的重定向没有触发,我只收到 404 错误而不是重定向到页面。


详情: 我们目前设置了一个多语言网站,例如 domain.com/English/Path/To/Page 和 domain.de/English /Path/To/Page,域。fr/English/Path/To/Page。我们的 CMS - Kentico - 设置为按照顶级域名进行翻译。 我们现在正在迁移到一个新站点,我们需要域。com/English/Path/To/Page 和域。de/German/Translated/Path/To/Page 和域。fr/French/Translated/Path/To/Page。 我相信以下是设置“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 等,其中每一个都对应于适当的使用输入值 {:{HTTP_HOST}} 中的引用语法重写映射(命名为 DERedirects、USRedirects、FRRedirects 等)。

说到底(当然还有很多语法错误,最终导致 500 个错误),这并没有在我身上崩溃或 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 以下)。

【问题讨论】:

    标签: .net iis url-rewriting


    【解决方案1】:

    找到我的答案!只需弄清楚/意识到“{:{HTTP_POST}}”作为输入是不可能的,然后我就可以正确搜索。找到这篇文章:

    http://forums.iis.net/t/1177509.aspx

    而且,如果它从互联网上消失,这里是复制/粘贴的版本:


    嗨,

    rewrite模块中request 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

    【讨论】:

      猜你喜欢
      • 2020-05-27
      • 2013-08-14
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-11
      相关资源
      最近更新 更多