Mikael Gidmark
Mikael Gidmark

Reputation: 1413

Force a language prefix in the url with Sitecore

Is there a setting to force the language in the URL? Like, if I browse to http://www.site.com, I should be redirected to http://www.site.com/en, as it is now I can see the start page without the language prefix.

The LinkManager is configured to always put in the prefix so all the links look fine at least.

Upvotes: 4

Views: 2247

Answers (2)

Martijn van der Put
Martijn van der Put

Reputation: 4082

Another way to use is our SEO Friendly URL Module.

This module implements a custom LinkProvider that provides SEO Friendly URL's and forces items to be accessed through their friendly URL.
So if an item is accessed without the language code in the URL (e.g. /my-item) the module will 301 redirect to the URL with language code (e.g. /en/my-item).
That is, if you have configured it to force friendly URL's (forceFriendlyUrl="true") and set languageEmbedding="always".

We use that module on our corporate website, so take a look at that to see it in action.

Upvotes: 6

dunston
dunston

Reputation: 2670

You can use ISS URL Rewrite to redirect / to /en

Install that module on the IIS, and setup a rule. It can be done from the IIS gui or from web.config

I am using this rule to do the same.

Insert the following configuration in the system.webServer section in web.config

<system.webServer>
    <rewrite>
        <rule name="redirert / to en" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{PATH_INFO}" pattern="^/$" />
                </conditions>
                <action type="Redirect" url="/en/" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

It will redirect every request hitten "/" to "/en"

Upvotes: 0

Related Questions