Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Lowercase URLs on Document Events View modes: 
User avatar
Certified Developer 11
Certified Developer 11
dfahy@ecentricarts.com - 7/3/2013 9:18:55 AM
   
Lowercase URLs on Document Events
Hi,

I have a client who is very specific about SEO and they do not want the extra 301 when redirecting to a lowercase url. They want all the URLs in their site to be lowercase .

I have written a SQL script to convert the following values to lowercase:
CMS_Tree.NodeAliasPath
CMS_Document.DocumentNamePath
CMS_Document.DocumentUrlPath
CMS_DocumentAlias.AliasURLPath

However, if any document in the tree is updated or a new document is created then these values will not be lowercase anymore.

I then thought that I could do this in the document events so I created a custom handler with the following code
[OnDocumentCreated]
public partial class CMSModuleLoader
{
public class OnDocumentCreatedAttribute : CMSLoaderAttribute
{
public override void Init()
{
base.Init();

DocumentEvents.Update.Before += UpdateBefore;

}

void UpdateBefore(object sender, DocumentEventArgs e)
{
e.Node.SetValue("NodeAliasPath", e.Node.NodeAliasPath.ToLower());
e.Node.SetValue("DocumentUrlPath", e.Node.DocumentUrlPath.ToLower());
e.Node.SetValue("DocumentNamePath", e.Node.DocumentNamePath.ToLower());
}
}
}

The UpdateBefore method fires on every document update but the values do not get changed to lowercase. Am I doing something wrong here? Can these values not be updated?

User avatar
Member
Member
kentico_sandroj - 7/3/2013 4:53:00 PM
   
RE:Lowercase URLs on Document Events
Hello,

So the issue here is that you were not converting the document name to lowercase which is being used to create the path for child documents. Also, the Update event only works for editing documents, you would have to use the Insert event for new documents. Please try the suggestion that I e-mailed to you and let me know if you have any trouble with it.

Thanks,
Sandro