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&$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&categoryid=$2&$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?