Reputation: 51
Our site uses "subfolders" for specifying languages (e.g. www.domain.com/nl or www.domain.com/en). The default language is Dutch (nl). Currently visitors are both able to visit pages via the specified language (e.g. www.domain.com/nl) or the root domain (e.g. www.domain.com).
For SEO purposes we want to redirect (enforce) all users visiting the root to the specificed language (nl) (e.g. www.domain.com/page/1 to www.domain.com/nl/page/1).
Previous approaches (using web.config rewrite rule) led to (infinite) loops (e.g. www.domain.com/nl/nl/nl/nl/nl/nl/nl/etc.).
I know this topic Rewrite Rule to enforce default lang code in URL describes how to do it in .htaccess, but I don't have a clue how to convert it to web.config.
Thanks in advance :-)
Upvotes: 0
Views: 361
Reputation: 4868
Try this
<configuration>
<system.webServer>
<rewrite>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_URI}" pattern="^/umbraco/" negate="true" /> <add input="{REQUEST_URI}" pattern="^/install/" negate="true" /> <add input="{REQUEST_URI}" pattern="^/nl/" negate="true" />
</conditions>
<rules>
<rule name="Language" stopProcessing="true">
<match url="^/nl" negate="true" />
<action type="Redirect" url="/nl/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The above rule will redirect all www.domain.com/sub/sub to www.domain.com/nl/sub/sub
Upvotes: 1