I wanted the UmanFriendlyUrls were also supported by 5.5.1 for multi-languages sites and I read here on the forum that other users wanted the same.
So I decided to write a patch to make this happen.
The final format of the URL will be: domain/culturecode/tabpath.aspx (http://example.com/en-gb/home.aspx)
The patch consists of a few lines of code that modify two files:
FriendlyUrlProvider (DotNetNuke.HttpModules)
From line 147
Public Overloads Overrides Function FriendlyUrl(ByVal tab As TabInfo, ByVal path As String, ByVal pageName As String, ByVal portalAlias As String) As String
Dim friendlyPath As String = path
Dim matchString As String = ""
Dim isPagePath As Boolean = tab IsNot Nothing
If (UrlFormat = UrlFormatType.HumanFriendly) Then
If (tab IsNot Nothing) Then
Dim queryStringDic As Dictionary(Of String, String) = GetQueryStringDictionary(path)
If (queryStringDic.Count = 0 OrElse (queryStringDic.Count = 1 AndAlso queryStringDic.ContainsKey("tabid"))) Then
'Return AddHTTP(portalAlias & "/" & tab.TabPath.Replace("//", "/").TrimStart(Convert.ToChar("/")) + ".aspx")
friendlyPath = GetFriendlyAlias("~/" & tab.TabPath.Replace("//", "/").TrimStart("/"c) + ".aspx", portalAlias, isPagePath)
ElseIf (queryStringDic.Count = 2 AndAlso queryStringDic.ContainsKey("tabid") AndAlso _
queryStringDic.ContainsKey("language")) Then
If Not tab.IsNeutralCulture Then
friendlyPath = GetFriendlyAlias("~/" & tab.CultureCode & "/" & tab.TabPath.Replace("//", "/").TrimStart("/"c) + ".aspx", portalAlias, isPagePath).ToLower
Else
friendlyPath = GetFriendlyAlias("~/" & queryStringDic("language") & "/" & tab.TabPath.Replace("//", "/").TrimStart("/"c) + ".aspx", portalAlias, isPagePath).ToLower
End If
Else
If (queryStringDic.ContainsKey("ctl")) AndAlso Not (queryStringDic.ContainsKey("language")) Then
Select Case queryStringDic("ctl")
Case "terms"
friendlyPath = GetFriendlyAlias("~/terms.aspx", portalAlias, isPagePath)
Case "privacy"
friendlyPath = GetFriendlyAlias("~/privacy.aspx", portalAlias, isPagePath)
Case "login"
If (queryStringDic.ContainsKey("returnurl")) Then
friendlyPath = GetFriendlyAlias("~/login.aspx?ReturnUrl=" & queryStringDic("returnurl"), portalAlias, isPagePath)
Else
friendlyPath = GetFriendlyAlias("~/login.aspx", portalAlias, isPagePath)
End If
Case "register"
If (queryStringDic.ContainsKey("returnurl")) Then
friendlyPath = GetFriendlyAlias("~/register.aspx?returnurl=" & queryStringDic("returnurl"), portalAlias, isPagePath)
Else
friendlyPath = GetFriendlyAlias("~/register.aspx", portalAlias, isPagePath)
End If
Case Else
'Return Search engine friendly version
Return GetFriendlyQueryString(tab, GetFriendlyAlias(path, portalAlias, isPagePath), pageName)
End Select
Else
'Return Search engine friendly version
Return GetFriendlyQueryString(tab, GetFriendlyAlias(path, portalAlias, isPagePath), pageName)
End If
End If
End If
Else
'Return Search engine friendly version
friendlyPath = GetFriendlyQueryString(tab, GetFriendlyAlias(path, portalAlias, isPagePath), pageName)
End If
friendlyPath = CheckPathLength(friendlyPath, path)
Return friendlyPath
End Function
UrlrewriteModule (DotNetNuke.HttpModules)
line 30
Imports DotNetNuke.Services.Localization
From line 194
' Default Page has been Requested
If (tabPath = "/" & glbDefaultPage.ToLower()) Then
Return
End If
'Start of patch
Dim CulturCode As String = String.Empty
Dim dicLocales As Dictionary(Of String, Locale) = LocaleController.Instance().GetLocales(portalID)
If dicLocales.Count > 1 Then
For Each CulturePart As String In splitUrl
If CulturePart.Length.Equals(5) Then
For Each key As KeyValuePair(Of String, Locale) In dicLocales
If key.Key.ToLower.Equals(CulturePart.ToLower) Then
CulturCode = key.Value.Code
tabPath = tabPath.Replace("/" & CulturePart, "")
Exit For
End If
Next
End If
Next
End If
' Check to see if the tab exists (if localization is enable, check for the specified culture)
Dim tabID As Integer = TabController.GetTabByTabPath(portalID, tabPath.Replace("/", "//").Replace(".aspx", ""), CulturCode)
' Check to see if neutral culture tab exists
If (tabID = Null.NullInteger And CulturCode.Length > 0) Then
tabID = TabController.GetTabByTabPath(portalID, tabPath.Replace("/", "//").Replace(".aspx", ""), "")
End If
'End of patch
If (tabID <> Null.NullInteger) Then
Dim sendToUrl As String = "~/" & glbDefaultPage & "?TabID=" & tabID.ToString()
If Not CulturCode.Equals(String.Empty) Then
.......
I tested it on my local app that contains my productions portals and for me work fine.
There is only a problem with neutral culture tabs, like admins tabs, that, after postback redirect to the wrong culture.
This is due to a 5.5.1 bug.
To fix it you must change the line 2189 in Library/Common/Globals.vb
From
cultureCode = Thread.CurrentThread.CurrentUICulture.Name
to
cultureCode = Thread.CurrentThread.CurrentCulture.Name
Feel free to test the patch on your local app and to improve it.
Let me know yours opinions.
Regards
Manzoni Fausto
|