IIS URL重写默认语言路径 [英] IIS URL Rewrite Default Language Path
问题描述
我正在尝试使一条规则起作用,从而使语言标识符位于url路径中.如果未指定语言,我们希望将网址强制为en版本.例如:
I'm trying to get a rule working whereby the language identifier is in the url path. We want to force the url to the en version if a language is not specified. For example:
www.domain.com/page.aspx应该重定向到www.domain.com/en/page.aspx
www.domain.com/page.aspx should redirect to 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?
推荐答案
将规则更改为:
<rule name="Default Language" stopProcessing="true">
<match url="^en/" negate="true" />
<action type="Redirect" url="/en/{R:0}" redirectType="Permanent" />
</rule>
它将检查url是否以 en/
开头,如果不是,它将在请求的路径前面附加 en/
.
It will check if the url starts with en/
and if not, it will append en/
in front of the requested path.
您进行了无限重定向,因为无论向哪个反向引用发送到/en/{R:1}
,它都与(.*)
匹配(因为它与任何内容都匹配)/一切).
You had an infinite redirection because whatever back reference was sent to /en/{R:1}
, it was matching (.*)
(as it matches anything/everything).
这篇关于IIS URL重写默认语言路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!