Language-specific URL's for SEO

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 лет назад
Both existing (1.9) and upcoming (2.0) versions of nopCommerce do not support language-specific URL's which makes it impossible to:
a) Provide language-specific URL's
b) Let search engines pick-up language-specific content for SEO
c) Generate Sitemaps for each of languages used

This topic is dedicated to resolving these issues and will provide working examples of how make it work
12 лет назад
I have tried to raise the same concern as part of other topics, but it seems that nopCommerce team has chosen to ignore this issue for now. Since I have partially solved this dilemma myself I will try to provide hints on how this can be done. All code pointers here are in reference of version 1.9, so newer BETA will need to be revisited again to get the same functionality going.

How is language switching working now?

nopCommerce maintains a cookie namely Nop.CustomerLanguage that stores a numeric language id. The same id is used for both Admin and Public site, so if you switch language in one place, it will affect language display in another.

So what's wrong with that you may ask?
For starters, this just annoying when you want your Admin pages to be in english, but public site to be in user-chosen language. Since cookies are not picked up by search engines, let's review more serious ramifications:

a) When search engine indexes your site how does it know what language to index? The answer is - it doesn't, so you end up being indexed just for default language.

b) Theoretically it could have been possible to avoid this situation if only sitemaps would generate language-specific URL's both for your products, categories, manufacturers, etc., but again they don't.

c) It would be nice if HTML language settings such as "lang" attribute and meta tags would reflect the proper language culture in the content, so that browser would render it right all the time, but this goes a bit beyond a scope of this topic.

What needs to be changed to fix it?
Primarily - the way language settings are preserved throughout a user session. The code that reads above mentioned cookie is sitting inside NopContext.cs file under WorkingLanguage property, this is where the magic happens. If you review the code yourself you will find setter/getter that sets the cookie as well as reads what that cookie stores on the client machine.

Language id as it's being used now has no particular value to search engines or users who view it, so it needs to be replaced by something more understandable/usable - language culture for example, so codes like "en-US", "ru-RU", etc.
This is brings us to the next step - if we decide to switch to culture codes - we need a way for the system to resolve those codes to Language (object used to retain all required information internally). Luckily this information is stored in the system and is readily available. The method to resolve the language by culture code will go into Directory/ILanguageService.cs and LanguageService.cs


        /// <summary>
        /// Gets a language
        /// </summary>
        /// <param name="cultureId">Language identifier (i.e. en-US)</param>
        /// <returns>Language</returns>
        public Language GetLanguageByCulture(string cultureId)
        {
            if (String.IsNullOrEmpty(cultureId))
                return null;            

            string key = string.Format(LANGUAGES_BY_CULTURE, cultureId);
            object obj2 = _cacheManager.Get(key);
            if (this.CacheEnabled && (obj2 != null))
            {
                return (Language)obj2;
            }

            var query = from l in _context.Languages
                        where l.LanguageCulture == cultureId
                        select l;
            var language = query.SingleOrDefault();

            if (this.CacheEnabled)
            {
                _cacheManager.Add(key, language);
            }
            return language;
        }


Merely changing the code here is not good enough since you want URL's to reflect what language it displays, so now you need to add an extra QueryString parameter to set the language and use URLRewrite to pick it up. Ideally you would want your URL to indicate your language at the top of the hierarchy (i.e. yoursite.com/en-us/products/id).
12 лет назад
Thanks for info. This task is already on our roadmap (one of the most awaited features). But it'll be completed a bit later
12 лет назад
It's great to know that this anticipated feature is in the works! Thank you! I will however post a few more code samples for those who can't wait too long :)
12 лет назад
This task is on the road map for a year now and it's status is "Closed". I'm using 1.9 and tried to stop myself from modifying the code to make it work. However i'm not willing to wait another year so i'll go for it.

At least storing the culture in the URL would make a huge difference for SEO.

also something like

site.com
de.site.com
it.site.com

would be great

Proton17, if you are going to publish more samples i definately wouldn't mind. Neither would many other people i think ;)
12 лет назад
norkor wrote:
This task is on the road map for a year now and it's status is "Closed"...

It's closed because it has been completed several days ago. This feature will be available in the upcoming 2.10 release
12 лет назад
That's great Andrei! I'll check the source code and try to implement it in 1.9. I'd use the 2.1. but i think the nop2 has some way to go performance wise.
12 лет назад
norkor wrote:
That's great Andrei! I'll check the source code and try to implement it in 1.9. I'd use the 2.1. but i think the nop2 has some way to go performance wise.

Performance optimization is included in 2.1 release (due by the end of august):
http://nopcommerce.codeplex.com/workitem/9645
12 лет назад
pretty impressive :) you put up some fast pace.. looking forward for the new release
12 лет назад
Hey there guys. I have been editing the Spanish language SEO's by category after enabling the second language within the settings. I chose Spanish Spain international. However, one odd thing. Whenever now I am in the admin console, I put it to Spanish and I get this:
Admin.Catalog.Categories.Manage (Admin.Catalog.Categories.SwitchToTreeView
Admin.Header.PublicStore | Admin.Header.ClearCache | Admin.Header.RestartApplication

It goes back to normal when I put it back to English. Not really important but what I am concerned about is getting the Spanish information down right. I put in an "es" as the separate identifier in the settings.

How do I create a sitemap for the spanish language?
And did I do anything right or wrong in my setup?

Thanks for all the support and help. Also, where can I get a book on the styles.css to learn the settings and be able to do some light editing of the pages appearance. This really interests me.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.