SEO and multilingual pages

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 лет назад
I do knot know what seem to be problem.

When I disable UrlRewriting everything works fine, when I enable it, when I go to another language that is not default, I have the problems.

I change a little bit a Nicolas code, so I have:
/// <summary>
        /// Gets category URL
        /// </summary>
        /// <param name="category">Category</param>
        /// <returns>Category URL</returns>
        public static string GetCategoryUrl(Category category, int languageId)
        {
            if (category == null)
                throw new ArgumentNullException("category");
            string seName = GetSEName(category.SEName);

            if (String.IsNullOrEmpty(seName))
            {
                var categoryLocalized = CategoryManager.GetCategoryLocalizedByCategoryIdAndLanguageId(category.CategoryId, languageId);
                if (categoryLocalized != null)
                {
                    seName = GetSEName(categoryLocalized.Name);
                }
                else
                {
                seName = GetSEName(category.Name);
                }
            }            

            int defaultLanguage = Convert.ToInt32(SettingManager.GetSettingValue("Localization.DefaultLanguageID"));
            string url = String.Empty;
            
            string url2 = String.Empty;
            if (languageId == defaultLanguage)
            {
                url2 = SEOHelper.EnableUrlRewriting ? SettingManager.GetSettingValue("SEO.Category.UrlRewriteFormat") : "{0}Category.aspx?CategoryID={1}";
                url = string.Format(url2, CommonHelper.GetStoreLocation(), category.CategoryId, seName);
            }
            else
            {
                url2 = SEOHelper.EnableUrlRewriting ? SettingManager.GetSettingValue("SEO.Category.UrlRewriteFormat2") : "{0}Category.aspx?Language={1}&CategoryID={2}";
                url = string.Format(url2, CommonHelper.GetStoreLocation(), GetLocaleSubFolder(languageId), category.CategoryId, seName);
            }
            return url.ToLowerInvariant();
        }


For SEO.Category.UrlRewriteFormat I have in database for default language: {0}c{1}/{2}

For SEO.Category.UrlRewriteFormat2 I have in database for other languages: {0}{1}/c{2}/{3}

In UrlRewriting.config I have for default language:
<add name="CategoryDetailsRewrite" virtualUrl="^~/c([0-9]*)/([\w-]*)"
         rewriteUrlParameter="ExcludeFromClientQueryString"
         destinationUrl="~/category.aspx?categoryid=$1&amp;$3"
         ignoreCase="true" />

with no url rewriting my link above look like
www.nopcomerce.com/category.aspx?categoryid=10&somecategory

and for other languages I have
<add name="CategoryDetailsRewrite2" virtualUrl="^~/[\w-]*/c([0-9]*)/([\w-]*)"
         rewriteUrlParameter="ExcludeFromClientQueryString"
         destinationUrl="~/category.aspx?language=$1&amp;categoryid=$2&amp;$4"
         ignoreCase="true" />

the link with no url rewrithing for other language look like
www.nopcomerce.com/category.aspx?language=de&categoryid=10&somecategorylocalizedingerman

The main idea is when I go to category in default language I will have link like
www.nopcomerce.com/c10/somecategory

And when I go to for example in same category in German I will have
www.nopcomerce.com/de/c10/somecategorylocalizedingerman

Now I know that page works fine, as I say before, because when I disable UrlRewriting page works fine. I can change language between categories, products and entire portal with no problem on every language

But when I enable UrlRewriting, the links for category's in default language works fine, but when i click on link's in other languages, every time I click some link for category in other language it redirect me to the home page.

I try everything but I do knot know what's to the problem. What is wrong?
13 лет назад
Can someone of NopCommerce team look at this and please help me?

Thanks in advance.
13 лет назад
After several days of torture and the many hours I gave up one thing, and it is that links will be as I want.

I never managed to do that links for languages, other than the default link, looks like:

nopcommerce.com / country / category / name-of-category


The closest I've managed to achieve is to link me look

nopcommerce.com / category / country / name-of-category.

I also managed to make the links that we are not classic ImageButton than regular hyperlink and links that I stumbled on an interesting problem.

NopCommerce use  cookie to change the language.

I found the name of the cookie, and as he writes it into NopContext.Current.WorkingLanguage.

In a similar way, I also created a javascript function setCookie ()

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}


which creates a log value of the selected language in the cookie and which activates when a user clicks on the flag of the selected language.

eg
string coockie = String.Format("javascript:setCookie('{0}','{1}','{2}');", "Nop.CustomerLanguage", language.LanguageId.ToString(), new TimeSpan(365, 0, 0, 0, 0));
hpLanguage.Attributes.Add("onclick", coockie);
hpLanguage.NavigateUrl = SEOHelper.GetCategoryUrl(category, languageId);


And now we come to the interesting part where the problem occurs and it is not clear to me why it happens.

Suppose we have German and English

When I first click on the flag of the German language, in the address bar shows me a link to the German language, but the content is still in English. Only when the second time, (again) I click the flag in the German language the content of the page is switch to German language.

I do not understand why this is happening now to me?
13 лет назад
I have seen this problem on another project: I was using current language and setting thread culture BEFORE setting the new value. Perhaps you should debug these two processes to see in which order they appears?

Good luck...
13 лет назад
I did not solve the problem yet. Currently I work on anther part of NopCommerce but when I finish I will start to work on that problem again.
13 лет назад
a.m. wrote:
It's better to do it with the urlrewrite (www.mystore.com/en/default.aspx and www.mystore.com/it/default.aspx)


Hello,

   I am trying to use NOP 1.9 but I don't know how to user SEO Urls with two languages. It always show SEO Url on English language.
   Can you help me on this problem.

Thanks,
Henry Nguyen
12 лет назад
does anyone found a solution for this issue ? I' m using nop 1.90 with 3 language (french, english and italian) and i really need to indicize all the languages on search engines...
12 лет назад
someone from nopcommerce development team could say something about it, isn't it?
12 лет назад
TRY to change

<add name="CategoryDetailsRewrite2" virtualUrl="^~/[\w-]*/c([0-9]*)/([\w-]*)"
         rewriteUrlParameter="ExcludeFromClientQueryString"
         destinationUrl="~/category.aspx?language=$1&amp;categoryid=$2&amp;$4"
         ignoreCase="true" />

to:

<add name="CategoryDetailsRewrite2" virtualUrl="^~/([\w-]*)/c([0-9]*)/([\w-]*)"
         rewriteUrlParameter="ExcludeFromClientQueryString"
         destinationUrl="~/category.aspx?language=$1&amp;categoryid=$2&amp;$4"
         ignoreCase="true" />

and it will be ok
12 лет назад
I have just implement this functionality to nop 1.9, it takes some time to rewrite classes but now it's working...soon will be demo ..
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.