Reputation: 461
we created multilingual website in FR, ES, EN from old classic asp website( which was also in 3 languages). In Old site by default in English language "en" was not embedding in the URL. but in our new sitecore website i have language Embedding="Always".
So when we redirect from old website to new website for 301 redirects in Google, if i opened my new website in French language and redirect from old site is in English ( which means that in the url there is no language i.e "en") link will point to french version).
So how could i add "en" to the url .
HttpContext.Current.Request.RawUrl
i can use above to get the raw url but i am not getting how to display "en" in the browser url.
old website links:
www.abc.com/xyz.asp,
www.abc.com/fr/xyz.asp,
www.abc.com/es/xyz.asp
new website links:
www.abc.com/en/xyz.aspx,
www.abc.com/fr/xyz.aspx,
www.abc.com/es/xyz.aspx
thanks
Upvotes: 4
Views: 9327
Reputation: 235
You can achieve this functionality by a sitecore setting.
Please refer above screenshot. Change languageEmbedding property to always from asNeeded This setting is done in Sitecore.config file. Please let me know if this helps you fulfill your requirement.
Upvotes: 0
Reputation: 2017
You can use URLOptions for this please see below code -
protected UrlOptions URLOptions
{
get
{
if (urlOptions == null)
{
urlOptions = new UrlOptions()
{
LanguageEmbedding = LanguageEmbedding.Always,
AddAspxExtension = false
};
}
return urlOptions;
}
}
Please pass this URloption object in geturl() function it will work.
LinkManager.GetItemUrl(itm, URLOptions)
Upvotes: 0
Reputation: 126
Take a look at Sitecore.Pipelines.PreprocessRequest.StripLanguage... I'd overwrite this one, if no language is found using the existing function, I'd default back to en.
Upvotes: 0
Reputation: 16990
How did you handle the language in the old website? How did you know a user was requesting a page in EN/FR/ES?
Since you are redirecting with a 301 from your old site you need to handle the language embedding into the URL from your old site. Handling it from the Sitecore side will add best only give you a "prettier" URL, with the added downside of having to add in another 302 redirect to the same page after you have inspected with the redirecting has the language embedded or not. Ruud's suggestion to use IIS Rewrite is a good one.
So when we redirect from old website to new website for 301 redirects in Google, if i opened my new website in French language and redirect from old site is in English ( which means that in the url there is no language i.e "en") link will point to french version).
Yes, this is how Sitecore works, it uses cookies to persist the last selected language, but context language is set in the following order. Your initial visit would set the language cookie.
Overriding Sitecore’s Logic to Determine the Context Language
If you really don't want the language persisted between browser sessions then override the Sitecore.Pipelines.HttpRequest.LanguageResolver
pipeline with your own logic to either NOT set the cookie (in which case you are totally relying on the request URL) OR set a cookie that will expire when the browser is closed. You can find an example from this blog post as well as an example in the previously linked John West blog post.
If your only concern is Google indexing, then I would probably not make any changes except add in a canonical link tags on your pages with the full URL including language (this will obviously be different for each language version).
<link rel="canonical" href="http://www.abc.com/en/xyz.aspx"/>
Upvotes: 3
Reputation: 8877
I don't know exactly what you're asking here, but if you need the URL with language embedding for a specific Sitecore item, you just need configure languageEmbedding="always"
for the link provider and then request the item's URL with the LinkManager:
Sitecore.Links.LinkManager.GetItemUrl(item);
If you need the URL for a specific language or explicitly set the languageEmbedding
option in your code, you can set that in the UrlOptions
:
var options = Sitecore.Links.LinkManager.GetDefaultUrlOptions();
options.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Always;
options.EmbedLanguage(Sitecore.Globalization.Language.Parse("en"));
Sitecore.Links.LinkManager.GetItemUrl(item, options);
Hope that helps!
Upvotes: 1