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
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.
The sc_lang query string parameter.
The language prefix in the path in the requested URL.
The language cookie associated with the context site.
The default language associated with the context logical site.
The DefaultLanguage setting specified in web.config.
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"/>
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!
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.
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)
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.
Related
Our company provides both a API and a small number of widgets that are embedded in clients websites through Iframes.
Now we have a Belgian customer who wishes to use our widgets. As you know Belgium is bi-lingual, so we are making liberal use of both the LocaleMiddleware and the {% trans 'string' %} tags.
Now as I understand correctly the middleware checks the URL to see which language to use. When you first visit our clients website you get a large pop-up where you choose your language. After this popup your url changes to this format: www.clientorg.be/fr_BE/rest-of-the-url, so that should (hopefully) work just fine.
However, our widget is served through an Iframe. (src = s2.oururl.com) which contains no language value.
So my question is: Will Django be able to detect the language of the user? Or will it only be able to check 'our' s2.url, meaning we need to contact our client and provide him with 2 urls to paste in the iframe, depending on the language the user chooses.
Here's exactly what LocalMiddleware tries to do to determine the language:
https://docs.djangoproject.com/en/2.0/topics/i18n/translation/
LocaleMiddleware tries to determine the user’s language preference by
following this algorithm:
First, it looks for the language prefix in the requested URL. This is
only performed when you are using the i18n_patterns function in your
root URLconf. See Internationalization: in URL patterns for more
information about the language prefix and how to internationalize URL
patterns.
Failing that, it looks for the LANGUAGE_SESSION_KEY key in the current
user’s session.
Failing that, it looks for a cookie.
The name of the cookie used is set by the LANGUAGE_COOKIE_NAME
setting. (The default name is django_language.)
Failing that, it looks at the Accept-Language HTTP header. This header
is sent by your browser and tells the server which language(s) you
prefer, in order by priority. Django tries each language in the header
until it finds one with available translations.
Failing that, it uses the global LANGUAGE_CODE setting.
The business has a requirement to always show the language in the URL for our CD sites. I did some research and set the LanguageEmbedding setting to always. This seems to work fine for non-default languages but not for English, which is the default language.
When I try to go to www.abc.com, shouldnt it change to www.abc.com/en ? Am I right to think this or is this how Sitecore will behave for default language where it won't show the language if its not an embedded links?
Thanks
When Sitecore determines your language via browser preference, cookie, URL slug, or query string, it will not redirect to that preferred URL structure with language slug.
You can either create a redirect module (i.e. if language context set, make correct URL and redirect) or write out <link langref=""> tags, which is an SEO best practice anyways.
OOTB that is the way that Sitecore works. When you have LanguageEmbedding="always" - the links should all be generated with the language embedded - including for en, so a link to the home page would be www.abc.com/en - but if you just visit the domain - www.abc.com - Sitecore then uses either the language cookie stored from your last visit, or the default language.
If you want the behavior to be that if you visit www.abc.com the user is always it would be better to set that up using an IIS Redirect or a rewrite .
I have installed Redirect module in sitecore. Inside modules I have created "Redirect Url". In Redirect Url I wrote Requested Url "http://domainname/pagename" and selected Redirect To from content. But it is not working. Can anyone tell me what is wrong I am doing?
I have created redirect pattern.
It all depends on which module implementation you are using. I have heard multiple complaints on functional of original one (seems it is discontinued at all), so people are doing their own forks. The best implementation for the day is by Chris Adams and Max Slabyak, the module with sources, packages as well as good documentation is available at GitHub and it is being maintained with time.
With that Redirect Module installed, I do the following:
Under /sitecore/system/Modules/Redirect Module folder in Sitecore create a new redirect pattern called Pagename Test
Set requested expression to ^/pagename/?
Leave response status code equal 301
Set source item to the actual page item serving that redirect request
Do not forget to publish redirect pattern (and module itself if not yet)
Then as I hit http://myhostname/pagename/ I am being redirected to desired page with 301 status code.
Hope this helps and please let us know if that worked out for you.
In the Sitecore sites I'm working on (6.5 and 6.6), I've noticed that all the sites have a page at /si that is the same as the home page, but with the content missing/hidden.
Does anyone else have a website with this page? Does anyone know what it is for?
This is Chinese version of the home page. The content is missing as there are no Chinese language specific fields filled with data, but the page itself may come from Standard values.
Most probably your LinkManager in Sitecore.config has the value of languageEmbedding property set to asNeeded or always.
Switching to never would solve this issue (as long as you're not using multilanguage versions of you pages and you need language in the url).
Here are some posts which gives some more input about LinkManager:
Patching the Linkmanager
Sitecore Language Embedding multiple sites
This is expected Sitecore behavior.
You can find the same "pages" with "it", "dk", "de", "se" and so on.
In the httpRequestBegin pipeline found in web.config you can see that Sitecore language resolver is kicking in before the item resolver does. Hence Sitecore interprets the request as a request for the home page in another language layer and any two-letter ISO code for language will return the home page in that specified language context.
You could implement your own processor before the language resolver if you want to handle requests for specific language codes in certain ways.
I'am new to Sitecore and had few questions on Multilingual sites in Sitecore
First I added the new language to the existing site and try to access the same with sc* parameter for testing purpose.
The site throws "Input string is in incorrect format" error. Though the content is not added for this it should be a blank page, not sure why it's throwing the error.
If, by chance, your Sitecore instance has multiple sites (i.e. you're using the SiteDefinition.config file to define separate site host headers) then you need to specify the language per-site, in the language attribute within the particular site node in SiteDefinition.config.
The value would be the language code, like "en-US" or "da-DK" for instance. For reference, see this (this references the web.config, but it applies to SiteDefinition.config as well).
besides the sc_lang query parameter, you can also give the language in the url.
for example /en leads to English homepage, /nl-NL to the dutch homepage. the first part of the url is the language.
so /en/page1.asp leads to the en version of the page1 item under your home.
The current language is stored in a cookie check the website#lang cookie.. Where website is the name of the website.
The default language is located in the web.config or include files
With the LinkManager in the web.config you can configer the appearance