[英]IIS URL Rewrite Default Language Path
I'm trying to get a rule working whereby the language identifier is in the url path. 我正在尝试使一条规则起作用,从而使语言标识符位于url路径中。 We want to force the url to the en version if a language is not specified. 如果未指定语言,我们希望将网址强制为en版本。 For example: 例如:
www.domain.com/page.aspx should redirect to www.domain.com/en/page.aspx www.domain.com/page.aspx应该重定向到www.domain.com/en/page.aspx
Here's the rule we have so far, but it keeps ending up in a redirect loop. 到目前为止,这是我们的规则,但始终以重定向循环结尾。
<rule name="Default Language" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/(en|es|ph)/" negate="true" ignoreCase="true" />
</conditions>
<action type="Redirect" url="/en/{R:1}" redirectType="Permanent" />
</rule>
Any ideas where it's going wrong? 任何想法哪里出了问题?
Change your rule to: 将规则更改为:
<rule name="Default Language" stopProcessing="true">
<match url="^en/" negate="true" />
<action type="Redirect" url="/en/{R:0}" redirectType="Permanent" />
</rule>
It will check if the url starts with en/
and if not, it will append en/
in front of the requested path. 它将检查url是否以en/
开头,如果不是,则将en/
附加在请求路径的前面。
You had an infinite redirection because whatever back reference was sent to /en/{R:1}
, it was matching (.*)
(as it matches anything/everything). 您进行了无限重定向,因为任何向/en/{R:1}
发送的反向引用都匹配(.*)
(因为它匹配任何内容/所有内容)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.