Search code examples
iisurl-rewritingasp.net-mvc-5

URL Rewrite multilingual site for default language in MVC 5


I have a multilingual site in MVC 5. I've implemented SEO friendly URL using attribute routing. Here are the sample URL:

http://mycompany.com/en
http://mycompany.com/en/about_us
http://mycompany.com/en/product/type/item

http://mycompany.com/fr
http://mycompany.com/fr/about_us
http://mycompany.com/fr/product/type/item

Now, I need to remove language code (en) for default language English.

How can I achieve that using IIS URL rewrite tool? Any alternate solution would work too.


Solution

  • You can try this rule. When user enters the url, it will be redirected to URL without language and show in the browser.

    <rule name="rule2" enabled="true" stopProcessing="true">
                    <match url="en(.*)" />
                    <action type="Redirect" url="{R:1}" />
    </rule>
    

    enter image description here