Force a language prefix in the url with Sitecore

。_饼干妹妹 提交于 2019-12-10 16:07:20

问题


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.


回答1:


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.




回答2:


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"



来源:https://stackoverflow.com/questions/21133820/force-a-language-prefix-in-the-url-with-sitecore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!