A quick look at various techniques for managing URLs in Sitefinity.
Using the Basic Built-In URL Management Tools
- Adding additional URLs to pages through Sitefinity page editor.
- Adding external redirect links through Sitefinity page editor.
Using urlRewriteFormat for existing modules
urlRewriteFormat parameters are found in the web.config file and applied to Generic Content-based modules.
Example: urlRewriteFormat="~/{Provider}/{LibraryName}/[Name].sflb.ashx"
[] - indicates meta field.
{} - indicates keyword that has hard-coded meaning for GC module.
Potential hard-coded items that can be used:
{ID} - hash code for content item (note the ID itself is not guaranteed to
be unique, it is used in case URL format generates duplicate URLs then this
ID is appended to the URL but you can also set it explicitly)
{GUID} - the actual (unique) ID of the content item
{Provider} - specifies data provider name
Library module overrides this method and adds additional keyword
{LibraryName} - specifies the name of the library
Refer to <metaFields> section in the web.config for reference on available meta fields.
To update old items touch each of them with this code:
protected void Page_Load(object sender, EventArgs e)
{
Telerik.Cms.Engine.ContentManager contentManager = new Telerik.Cms.Engine.ContentManager("News");
IList news = contentManager.GetContent();
foreach (Telerik.Cms.Engine.IContent newsItem in news)
{
string title = newsItem.GetMetaData("Title").ToString();
Response.Write(" - " + title + "<br/>");
Telerik.Cms.Engine.IContent updateItem = contentManager.GetContent(newsItem.ID);
updateItem.SetMetaData("Title", title);
contentManager.SaveContent(updateItem);
}
}
More information on updating existing items can be found here:
http://www.sitefinity.com/help/developer-manual/content-items-update.html
http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bddgkt.aspx
Using AdvancedUrlRewriter
1. Add a configuration section element (<configSections>):
<configSections>
<sectionGroup name="telerik">
...
<section name="urlrewrites" type="Telerik.Cms.Web.AdvancedUrlRewriter, Telerik.Cms"/>
...
</sectionGroup>
</configSections>
2. Replace the default CmsHttpModule with CmsHttpModuleUrlRewrite:
<httpModules>
<add name="Cms" type="Telerik.Cms.Web.CmsHttpModuleUrlRewrite, Telerik.Cms"/>
</httpModules>
3. Add a <urlrewrites> section:
<telerik>
..
<urlrewrites>
<!-- Add your rule elements here -->
<rule>
<url>[input URL pattern]</url>
<rewrite>[replaced URL]</rewrite>
</rule>
</urlrewrites>
..
</telerik>
There is an entire section devoted to URL rewriting in the Sitefinity User Manual:
http://www.sitefinity.com/documents/UserManual_3_5.pdf
Forum thread describing how to setup:
http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-tabbb.aspx
How to setup if using IIS 7 with integrated pipeline mode:
http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-btkatb.aspx
More information on integrated pipeline mode:
http://www.code-magazine.com/Article.aspx?quickid=060103
.NET Regular Expressions:
http://msdn.microsoft.com/en-us/library/hs600312(VS.71).aspx
Example Rewriting Rules:
<urlrewrites>
<rule>
<url>Getting_Started_with_Open_Access\.aspx</url>
<rewrite>Getting_Started_with_OpenAccess.aspx</rewrite>
</rule>
<rule>
<url>/urlrewriting\-done/(\d\d\-\d\d\-\d\d)</url>
<rewrite>/urlrewriting-done/news/$1</rewrite>
</rule>
</urlrewrites>
Using a Custom HttpModule
Information about Permanent HTTP 301 Redirects:
http://www.webconfs.com/how-to-redirect-a-webpage.php
Forum thread on this subject:
http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bkeaah.aspx
Create ~/App_Code/PermanentRedirectHttpModule.cs
using System;
using System.Web;
namespace Custom
{
public class PermanentRedirectHttpModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
HttpRequest request = context.Request;
if (request.Url.PathAndQuery.Contains("Getting_Started_with_Open_Access.aspx"))
{
string url = request.Url.ToString();
url = url.Replace("Open_Access.aspx", "OpenAccess.aspx");
context.Response.Status="301 Moved Permanently";
context.Response.AddHeader("Location", url);
context.Response.End();
}
}
}
}
Add this module to the <httpModules> section in ~/web.config:
<httpModules>
...
<add name="PermanentRedirectHttpModule" type="Custom.PermanentRedirectHttpModule, App_Code" />
...
</httpModules>
Using the ReplaceTool
Download tool at:
http://www.sitefinitywatch.com/Libraries/Downloads/ReplaceTool.sflb.ashx
BE SURE TO BACKUP YOUR DATABASE BEFORE EVEN LOOKING AT THIS
1. Extract [Archive]\App_Code\ReplaceTool.cs file to ~/App_Code directory
2. Extract [Archive]\Tools directory to your ~/Tools directory. If you do not have Tools directory, please create it.
3. Open your web.config file, and add the highlighted line to the <tools> node:
<tools>
...
<add type="Telerik.Cms.Tools.ReplaceTool, App_Code" />
...
</tools>
Login to the Sitefinity Admin and navigate to Administration -> Tools -> ReplaceTool.
Random Stuff
Visual Studio theme:
http://www.agileprogrammer.com/dotnetguy/archive/2006/09/07/19030.aspx