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.