开发者

ASP.NET MVC 2: Make culture dependent redirect before routes kick in. For example: /Home => /en/us/Home

I want to make some redirects:

/Home => /en/us/Home
/ => en/us/

Where should I put these redirects and how should I redirect to avoid getting an infinite loop? Instead en/us I want to extract the values that the users browser i开发者_如何学Gos submitting.

Thank you for your Help!


These things go into web.config. Look at this article. This is for IIS7, but I think II6 supports this as well.

In your case you would add something like this into web.config:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="rule1" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{URL}" pattern="^en/us/?" negate="true" />
                </conditions>
                <action type="Redirect" url="/en/us/{R:0}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

This will catch all your non /en/us URLs and redirect them to the URL that starts with /en/us/ and what ever was in the original URL.

Note that this does not have the ability to test for actual location of the user. For that you'd probably have to use some logic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜