用于语言和新域的IIS重写规则 [英] IIS Rewrite rules for languages and new domains
问题描述
对于以下情况,我需要创建一些规则(我认为2个就足够了):
I need to create some rules (I thought that 2 would suffice) for the following scenarios:
A.第一种情况
https://www.mydomainOLD.com/en/lorem/ipsum /doloret/etc 到 https://www.mydomainNEW.com/lorem /ipsum/doloret/etc
基本上,我需要将域从 mydomainOLD 更改为 mydomainNEW ,并删除"/en/"从URL出现时.
Basically, I need to change the domain from mydomainOLD to mydomainNEW and remove "/en/" from URL when it appears.
我创建的规则如下:
<rule name="Replace OLD with NEW and remove /en/" enabled="true" stopProcessing="true">
<match url="^(http|https)://?(www.)mydomainOLD.com/en?(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false" />
<action type="Redirect" url="https://www.mydomainNEW.com/{R:3}" />
</rule>
B.第二种情况:
https://es.mydomainOLD.com/en/lorem/ipsum /doloret/etc 到 https://es.mydomainNEW.com /en/lorem/ipsum/doloret/etc
在这种情况下,用"es"代替"es".我也可以有其他国家/地区(fr,de,hk等)
In this case, instead of "es" I can have other countries as well (fr, de, hk, etc.)
我创建的规则如下(针对每个国家/地区):
The rule I created is the following (for each country):
<rule name="ES redirect from OLD to NEW" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(.*)es.mydomainOLD(.*)$" />
</conditions>
<action type="Redirect" url="{C:1}be.mydomainNEW.com{C:2}" appendQueryString="false" />
</rule>
即使当我测试正则表达式时,这些规则都无法按我期望的那样工作.我认为条件输入中还有更多我想念的东西.一点帮助将是不胜欢迎的.谢谢.
None of these rules are not working as I wanted, even if when I test the regex they work as expected. I think there's something more on the Condition Input that I'm missing. A bit of help would be more than welcome. Thanks.
推荐答案
请针对/en/
<rule name="rewrite rule" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{URL}" pattern="^/en/(.*)" />
<add input="{HTTP_HOST}" pattern="(www.)?mydomainOLD.com" />
</conditions>
<action type="Redirect" url="https://www.mydomainNEW.com/{C:1}" redirectType="Temporary" />
</rule>
对于从old/en/到new/en/或old/fr到old/fr的某人,请应用此一个.
For somelike old/en/ to new/en/ or old/fr to old/fr, please apply this one.
<rule name="rewrite rule" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{URL}" pattern="^/([a-z]{2}/.*)" />
<add input="{HTTP_HOST}" pattern="es.mydomainOLD.com" />
</conditions>
<action type="Redirect" url="https://es.mydomainNEW.com/{C:1}" redirectType="Temporary" />
</rule>
更新: 如果您需要将(es/fr/de/hk).mydomainold.com重定向到(es/fr/de/hk).mydomainnew.com.请尝试这个
Update: If you need to redirect (es/fr/de/hk).mydomainold.com to (es/fr/de/hk).mydomainnew.com. Please try this
<rule name="rewrite rule" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="([a-zA-Z]{2})\.mydomainOLD.com" />
</conditions>
<action type="Redirect" url="https://{C:1}.mydomainNEW.com/{R:0}" redirectType="Temporary" />
</rule>
这篇关于用于语言和新域的IIS重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!