[英]Redirect (web.config) rule to enforce subdirectory
我们的网站使用“子文件夹”来指定语言(例如www.domain.com/nl或www.domain.com/en)。 默认语言是荷兰语(nl)。 当前,访问者都可以通过指定的语言(例如,www.domain.com / nl)或根域(例如,www.domain.com)来访问页面。
出于SEO的目的,我们希望将所有访问根目录的用户重定向(强制)到特定的语言(nl)(例如www.domain.com/page/1到www.domain.com/nl/page/1)。
先前的方法(使用web.config重写规则)导致(无限)循环(例如,www.domain.com / nl / nl / nl / nl / nl / nl / nl / nl / etc等)。
我知道本主题“ 重写规则”以强制URL中的默认语言代码描述了如何在.htaccess中进行操作,但是我不知道如何将其转换为web.config。
提前致谢 :-)
尝试这个
<configuration>
<system.webServer>
<rewrite>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_URI}" pattern="^/umbraco/" negate="true" /> <add input="{REQUEST_URI}" pattern="^/install/" negate="true" /> <add input="{REQUEST_URI}" pattern="^/nl/" negate="true" />
</conditions>
<rules>
<rule name="Language" stopProcessing="true">
<match url="^/nl" negate="true" />
<action type="Redirect" url="/nl/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
上面的规则会将所有www.domain.com/sub/sub重定向到www.domain.com/nl/sub/sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.