设置URL重写规则

时间:2016-08-26 09:44:31

标签: asp.net asp.net-mvc iis url-rewriting asp.net-mvc-routing

我在我的web.config中有一个重写角色,并且它已重定向到mydomain.com/de。

但是现在我将使用用户语言替换操作de/{R:1},我可以从{HTTP_ACCEPT_LANGUAGE}获取。但这是一串语言,看起来像fr-CH,**fr**;q=0.8,en;q=0.6,de;q=0.4,de-CH;q=0.2/

那么有可能只得到这个字符串的**fr**吗?

感谢您的帮助。

这是我的角色:

<rule name="mydomain.com" stopProcessing="true" >
    <match url="(.*)" />
        <conditions>
            <add input="{URL}" pattern="/en/|/de/" negate="true" />
        </conditions>
        <action type="Redirect" url="de/{R:1}"  />
</rule>

1 个答案:

答案 0 :(得分:0)

过去,我使用以下规则重定向到基于语言的页面

<rewrite>           
        <rules>               
            <rule name="RedirectToLang" enabled="true" stopProcessing="true">
                <match url=".*" />
                <action type="Redirect" url="{R:0}/{HTTP_ACCEPT_LANGUAGE}" appendQueryString="true" />
                <conditions>
                    <add input="{HTTP_ACCEPT_LANGUAGE}" pattern=".+" />
                </conditions>
            </rule>
        </rules> 
    </rewrite>
相关问题