【问题标题】:Setting up URL Rewrite rule设置 URL 重写规则
【发布时间】:2017-01-02 22:48:19
【问题描述】:

我的 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>

【问题讨论】:

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


    【解决方案1】:

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

    <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>
    

    【讨论】:

      猜你喜欢
      • 2013-06-08
      • 2021-09-09
      • 2016-10-17
      • 2012-11-05
      • 2018-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多