简体   繁体   中英

IIS URL Rewrite Default Language Path

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

Change your rule to:

<rule name="Default Language" stopProcessing="true">
    <match url="^en/" negate="true" />
    <action type="Redirect" url="/en/{R:0}" redirectType="Permanent" />
</rule>

It will check if the url starts with en/ and if not, it will append en/ in front of the requested path.

You had an infinite redirection because whatever back reference was sent to /en/{R:1} , it was matching (.*) (as it matches anything/everything).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM