Sitefinity ASP.NET CMS
Skip Navigation LinksSupport / Knowledge Base / 301 Redirect - .HTML and other page types to .ASPX

301 Redirect - .HTML and other page types to .ASPX

Introduction

Many Sitefinity clients migrate static websites to Sitefinity. As a result, they might keep the domain name, but remove the HTML pages, for example, by creating .ASPX pages in Sitefinity. Pages from the old site might exist on Google © and when someone searches for your website, by clicking on the HTML page, it no longer exists. In this case, you need a URL redirect and this can be done by creating additional page URLs in Sitefinity, programming an HTTP Module, using Sitefinity's URL Rewrite engine, or adding a URL redirect to a static HTML page.

URLs and Sitefinity
By default, Sitefinity only handles one page extension at one time. You can have multiple URLs extensions for a page using the additionalExtensions property in the <cms> section of the Web.config. You can set the page extension for all pages using the pageExtension property in the same area. To customize this properties, follow these steps:

  1. Open the Web.config of your project
  2. Find the CMS tag
  3. Customize the section as shown below:

<cms defaultProvider="Sitefinity" pageExtension=".aspx" additionalExtensions=".html, .php" disabled="false" 
      pageEditorUIMode="Overlay"

  4.   Login to your Sitefinity project
  5.   Click on the pages tab
  6.   Click on a page
  7.   Click on the properties tab on the right
  8.   Click more options
  9.   Add new URLs as shown below:

 

Redirection with Meta Tags  - Creating the HTML Page

One advantage of this approach is that you can send a user to a specific page when a certain page is requested, without having to alter the Web.config or create a HTTP Handler. If you have multiple pages, however, this approach could be inefficient.

Here are the steps to perform a meta tags redirction

  1. Create an HTML page in the same directory with the same name as the old page, in your Sitefinity project.
  2. In between the head tags, add this code:
<meta http-equiv="refresh" content="0;url=http://www.mysite.com/mypage.aspx"
 

The link you see above is where the user will go, once the HTML page is visited. Here is the end result:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head> 
<meta http-equiv="refresh" content="0;url=http://www.mysite.com/mypage.aspx"
 
    <title></title
</head> 
<body> 
 
</body> 
</html> 

Creating an HTTP Module

This approach would allow you to redirect any request to a specific page. To implement this approach, follow these instructions:

1. In your App_Code folder, create a new class that inherits from IHTTPModule
2. In the Begin Request event, add logic to redirect the user as shown below:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
  
/// <summary>  
/// Summary description for MyHttpModule  
/// </summary>  
public class MyHttpModule :IHttpModule  
{  
    public MyHttpModule()  
    {  
        //  
        // TODO: Add constructor logic here  
        //  
    }  
    #region IHttpModule Members  
  
    public void Dispose()  
    {  
          
    }  
  
    public void Init(HttpApplication context)  
    {  
        context.BeginRequest += new EventHandler(context_BeginRequest);  
    }  
  
    void context_BeginRequest(object sender, EventArgs e)  
    {  
        HttpContext mycontext = HttpContext.Current;  
        if (mycontext.Request.RawUrl.Contains("/domain/Default.html"))  
        {  
            string redirectUrl = mycontext.Request.Url.ToString().Replace("/domain/Default.html""domain/default.aspx");  
            mycontext.Response.Redirect(redirectUrl);  
        }  
    }  
    #endregion  
}  


3. In your Web.config, register your HTTP Module:

<httpModules>  
      <add name="MyHttpModule" type="MyHttpModule, App_Code" />  

For more info on creating custom HTTP Modules, please refer to this article.

Regular Expressions

Sitefinity includes a URL re-writer tool that uses regular expressions. Here is a code sample:

 <telerik>  
    <urlrewrites>  
      <!-- Add your rule elements here -->  
      <rule>  
        <url>/[^/]+\.html</url>  
        <rewrite>/service/$1/$1\.aspx</rewrite>  
      </rule>  
    </urlrewrites>  

The rule is what the URL Rewriter should look fro in the URL. The <rewrite> attribute is what the new URL will be. For more info on using this tool, please refer to URL Rewriting in our User Manual.

Article Info

Article relates to 3.5 and above
Created by Joseph Anderson
Last modified by Joseph Anderson
Related categories: Deployment

About Telerik

Telerik, the publisher of Sitefinity CMS, is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting and .NET ORMTFSCode Analysis and Web Application Testing tools. Building on its solid expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Created with passion, Telerik products help thousands of developers every day to be more productive and deliver reliable applications under budget and on time. Read more about Telerik

Copyright © 2002-2010 Telerik. All rights reserved. Powered by Sitefinity