// you’re reading...

CMS

RedDot & 301 Redirects: How to manage 301’s within your RedDot CMS projects


One of the biggest risks when relaunching a new version of a site is losing search rankings that may have taken a considerable amount of time and effort to earn. The use of 301 Redirects will help you to maintain current search rankings for an existing site, particularly if the site structure has gone under the knife! Existing pages may have been relocated or consolidated to a new area of the site – or may have been removed altogether.

What exactly is a 301 redirect?

A 301 redirect instructs search engines that a URL’s name has changed perminantely. All previous information held about this page, including all it’s incoming link value and most important search engine position is to be transfered to a new page name.

Unfortunately 301 redirects cannot be managed straight out of box within RedDot CMS – since they need to be handled on the live web server. Fortunately, through the use of some basic server code integrated into your site templates, 301 redirects can be managed quite easily by content editors and administrators.

301 Redirects within RedDot CMS

For most RedDot CMS projects I have implemented in the past, I have found it easiest to manage all 301 redirects for a site within a custom 404 error page (every site should have a custom 404 error page anyway!). Not only does the page enable Users to manage the content for the 404 error page (try and be as creative as you can in this department!!!), it also doubles as an area to handle the required 301 redirects for the site. If a page is requested that does not exist or is no longer available, the web server will serve up the 404 error page which will enable the code for the 301 redirects to kick in if a match is found against the initial page request.

How does it work?

The key concept here is that we are creating a searchable table or list of 301 redirects that is matched against the initial page request. If a match is found, the user is redirected to the new page otherwise the 404 error page is displayed instead.

In this example I’ve used some C#.NET code to handle the 301 redirects, however the concept can quite easily be translated to any other language.

Here’s how to do it:

1. Create a new foundation template within your project specifically to manage a custom 404 error page:

<%@ Page Language="C#" AutoEventWireup="true" %>
<%
String pageRequested = "";
Dictionary redirects = new Dictionary();

pageRequested = Request["aspxerrorpath"].ToString().ToLower();

// remove querystring variables (if any)
if (pageRequested.IndexOf("?") > -1 )
{
pageRequested = pageRequested.Substring(0, pageRequested.IndexOf("?"));
}
%>

<h1>404 Error Page</h1>

<!IoRangeRedDotMode>
<div class="RedDot"><!IoRedDotOpenPage> [edit page]</div>
<!/IoRangeRedDotMode>
<h1>404 Error Page</h1>
<!IoRangeRedDotEditOnly>
<div class="RedDot"><!IoRedDot_txt_404errormessage> [default error message]</div>
<!/IoRangeRedDotEditOnly>
<%txt_404errormessage%>

<!IoRangeRedDotEditOnly>
<div class="RedDot"><!IoRedDot_con_301redirects> [maintain 301 redirects]</div>
<!/IoRangeRedDotEditOnly>
<%con_301redirects%>

<%
// perform redirect if match is found
if (redirects.ContainsKey(pageRequested))
{
Response.Clear();
Response.StatusCode = 301;
Response.AddHeader("Location", redirects[pageRequested]);
Response.End();
}
%>

Heres a break down of whats going on:

pageRequested = Request["aspxerrorpath"].ToString().ToLower();

Obtain URL of page that does not exist

if (pageRequested.IndexOf("?") > -1 )
{
pageRequested = pageRequested.Substring(0, pageRequested.IndexOf("?"));
}
%>

Remove any querystring variables from the page since we wont be matching against those

<%txt_404errormessage%>
Custom error message to be displayed on the 404 error page if no 301 redirect matches were found.

<%con_301redirects%>
Container where all of the 301 redirects are managed within the project.

if (redirects.ContainsKey(pageRequested))
{
Response.Clear();
Response.StatusCode = 301;
Response.AddHeader("Location", redirects[pageRequested]);
Response.End();
}

Find any matches against the page request and redirect the user to the new page

2. Create a new template which will enable users to create each of the individual 301 redirects. Each page created from this template will be connected up within the ‘con_301redirects’ container on the 404 error page

<reddot:cms>
    <if>
        <query valuea="Context:CurrentRenderMode" operator="==" valueb="Int:2">
            <htmltext>

                <%
                ' add new redirect
                if ("<%stf_oldurl%>" != "")
                {
                    redirects.Add("<%stf_oldurl%>".ToLower(), "<%anc_newurl%>");
                }
                %>

 </htmltext>
        </query>
    </if>
</reddot:cms>

<!IoRangeRedDotMode>
<div class="RedDot"><!IoRedDotOpenPage> [edit 301 redirect]
<!IoRangeRedDotEditOnly><span class="details"><span class="details-title">TITLE:</span> <%hdl_pagetitle%> | <span class="details-title">ID:</span> <%info_pageid%></span><!/IoRangeRedDotEditOnly></div>
<!IoRangeRedDotEditOnly>
<div class="RedDot"><!IoRedDot_stf_oldurl> [old URL]</div>
old URL: <%stf_oldurl%>

<!IoRangeRedDotEditOnly>
<div class="RedDot"><!IoRedDot_anc_newurl> [new URL]</div>
<!/IoRangeRedDotEditOnly>
new URL: <!IoRangeDynLink><a href="<%anc_newurl%>"><%hdl_pagetitle%></a>
<!/IoRangeDynLink>

<!/IoRangeRedDotMode>

Within RedDot, users enter in the ‘old’ and ‘new’ urls for the 301 redirect using the corresponding RedDot placeholders above.
When the page is published, the 301 redirect will be used to build up searchable table (in this example I’m using the C# Dictionary object) against which a match can be found based on the page request.

Extending things further

This is just a basic example of how you can manage 301 redirects within your RedDot CMS projects. I’m currently working on providing a feature to enable CMS users manage 301’s within individual site pages (rather than the 404 page), which in turn populates an XML document that contains all 301 redirects for the site. Watch this space…!

Download the templates used in this example (ZIP, 3Kb)

Share and Enjoy:
  • Print
  • email
  • Twitter
  • Digg
  • Reddit
  • StumbleUpon
  • Google Bookmarks
  • del.icio.us
  • MisterWong
  • Facebook
  • LinkedIn

No related posts.

About the author:

Kim Dezen Kim Dezen is a Senior RedDot CMS (Open Text Web Solutions) CMS Consultant, Developer and Freelancer. Part time DJ and obsessed music / vinyl junkie. Follow me on Twitter: @kimdezen                  Check out my blog: http://www.kimdezen.com for all things related to Red Dot, SEO/SEM and Web Development.

Discussion

2 comments for “RedDot & 301 Redirects: How to manage 301’s within your RedDot CMS projects”

  1. Don’t forget: to get the page running you need to set your IIS 404 page to the URL of your error page.
    You also might have to change the web.config in order to show customerrors for 404 pages.

    Posted by Markus Giesen | February 15, 2011, 6:14 am
  2. make sure you add this within your web.config file:

    <customErrors defaultRedirect=" insert page filename here " mode="On">
    <error statusCode="500" redirect=" insert page filename here " />
    <error statusCode="404" redirect=" insert page filename here " />
    <error statusCode="403" redirect=" insert page filename here " />
    </customErrors>

    Posted by Kim Dezen | February 16, 2011, 9:28 am

Post a comment



Stay up to date! - Get notified about followup comments

If you don't feel the urge to comment but wish to stay in the loop:
Just enter your email and subscribe to new comments.

Subscribe without commenting

Recent Tweets

  • RT @AirKraft: Transport Canada breakout: they manage 80K pages and 300K assets with WSM(RedDot). Wow! #OTCW 2010-11-11
  • The RedDot usergroup session 'Future of WCM' is in National Harbor 7, now. See you there! #otcw 2010-11-11
  • RT @yttergren: @AirKraft: Calling all WSM(RedDot) devs: share your solutions on http://bit.ly/bgPIof EVERY solution can win an iPad #OTCW 2010-11-10
  • Come to the Solution Exchange session. Enhance your (#reddot) CMS project! Chesapeake 12, 3:20pm #otcw Looking forward to see you there! 2010-11-10
  • More updates...