繁体   English   中英

IIS 重写 - 将站点重定向到新域捕获嵌入在 URL 中的语言

[英]IIS Rewrite - redirect site to new domain capturing the language embedded in the URL

我正在尝试编写一个正则表达式来将 URL 重定向到一个新域。 我为此写了 IIS 重写规则:

<rule name="Redirect to new domain" stopProcessing="true">
          <match url="^(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^(www\.)?my-www-en\.sites\.company\.net(\/([a-zA-Z]{2,3}-[a-zA-Z]{2,3}|en)\/?)?(.*$)" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="https://my-new-domain.com/en-us/{C:4}" appendQueryString="true" />
</rule>

当语言没有添加到初始 URL 时,它工作正常,但是,一些页面在域之后添加了语言,最终导致双语言外观 URL。所以基本上我想重定向这样的东西:

my-www-en.sites.company.net/some-page/another/page/
www.my-www-en.sites.company.net/some-page/another/page/
my-www-en.sites.company.net/de-de/some-page/another/page/
www.my-www-en.sites.company.net/de-de/some-page/another/page/
my-www-en.sites.company.net/en/some-page/another/page/

重定向到:

https://my-new-domain.com/en-us/some-page/another/page/

我当前的正则表达式没有正确捕获这些组(即使它在测试 IIS 重写中的正则表达式时也是如此)而且我很难让它工作。 现在一切都被重定向到主页而不是特定的网站。 能否请你帮忙?

请试试这个规则。 正则表达式可以匹配上面所有的 url。

<rule name="test">
                <match url=".*" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^(www\.)?my-www-en\.sites\.company\.net$" />
                    <add input="{REQUEST_URI}" pattern="(/.*)?(/some-page/another/page/)" />
                </conditions>
                <action type="Rewrite" url="https://my-new-domain.com/en-us{C:2}" />

您可以将重写更改为重定向。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM