27
Mar
08

Change sitecore’s file extension from aspx to html

Hey folks,

some guys want to use .html extensions instead of .aspx extensions; maybe it’s better for search engines, but that will be always a miracle.

For incoming requests we use ISAPI_Rewrite with a regular expression. And in fact of that we don’t want to replace all sc:link / sc:path functions in the renderings I overwrite the XslHelper function. A very tricky thing is the <sc:link /> method, which only converts the request to a xsl:value-of select and pass it to sc:StartLink().

Here we go:
You have to create a new class and inherit it by the sitecore’s XslHelper:

public class ScXslHelper : Sitecore.Xml.Xsl.XslHelper

You have to override three methods:

public override string path(System.Xml.XPath.XPathNodeIterator iterator)
{
string path = base.path(iterator);
string newPath = path.Replace(”.aspx”, “.html”);
return newPath;
}

public override string link(string fieldName, System.Xml.XPath.XPathNodeIterator iterator, string parameters)
{
string path = base.link(fieldName, iterator, parameters);
string newPath = path.Replace(”.aspx”, “.html”);
return newPath;
}

public override string StartLink(System.Xml.XPath.XPathNodeIterator iterator, string parameters)
{
string path = base.StartLink(iterator, parameters);
string newPath = path.Replace(”.aspx”, “.html”);
return newPath;
}

This solution is just basic, and should demonstrate the way you have to go. There is just one more function where you can generate a link and that is item.Paths.GetFriendlyUrl(), I suggest you should create a new class which extends the Sitecore.Data.ItemPath class.

Happy coding :-) cheers chris

//update:
I forgot to mention that you have to change the web.config entry for the helper under the xslExtension node:

<extension mode=”on” type=”Sitecore.Xml.Xsl.XslHelper, Sitecore.Kernel” namespace=”http://www.sitecore.net/sc” singleInstance=”true”></extension>

to your class name and your assembly name. Leave the namespace the same.



go back // go to overview

2 Responses to “Change sitecore's file extension from aspx to html”


  1. 1 kasper Aug 3rd, 2008 at 8:20 pm

    Thanx chris.
    actually, a nice and helpful post.

  2. 2 simi May 26th, 2009 at 9:30 am

    Thanks for your Post.I have one doubt how i use this assembly .You rare not given the assembly.

Leave a Reply




September 2010
M T W T F S S
« Mar    
 12345
6789101112
13141516171819
20212223242526
27282930  

Recent Entries