iFinity Blogs 

Jun 23

Written by: Bruce Chapman
Tuesday, June 23, 2009 6:01 PM 

This is becoming a very common help request for me lately, as increasing numbers of people convert old html (and asp and php) based websites into DotNetNuke based websites to take advantage of the extra power of the DNN framework.  The problem occurs that many Html based websites have been around a long time and generally rank well in search indexes.  Typically, the site owner wants to make sure that none of that existing ranking and associated traffic is lost when converting to a new DotNetNuke site.

This post will cover all of the steps necessary to divert traffic away from an old html based website to a new, DotNetNuke based website.  If you have an old .asp or .php based website, the instructions are virtually the same with just the file extensions changed.

0. Do your backups.

You're going to be modifying the web.config file, so take a backup of this file before you start.  If you mess it up, getting it all back will be as simple as restoring your previous web.config file.

1. Install the Url Master software

You can download and install the software from the Url Master Product Page : it's free to trial, and if you are working on a live website, you can get a free trial licence to use on your live site.

Install the Url Master software as per the instructions.  Of course, this is going to change your site to use Friendly Urls, but if you're interested in maintaining your existing links, then you'll at least want to make sure they are supported, and this means friendly urls!   That's assuming you didn't name your existing .html files "tabid-123-ctl-view-display.htm" instead of "product-information.html" like a sane person.

2. Plan your redirects

If you have a series of .html files 'out there' indexed, bookmarked and generally known by people on the internet, you're going to want to capture those and '301' redirect them to somewhere else, should they be requested.  This does two things : by using a 301 redirect, you will update the Search Engine indexes to your new locations, and any users using an old link from a bookmark or other website will still end up where you want them to be.

However, if you're going to move away from existing known urls to new ones, you need to plan which ones to capture.  The easiest way to do this is to do a search in search engines for indexed pages.  A simple site:domain.com search in Google will turn up the majority of indexed links.  You can also go back through your site logs using an log analyser, or do a site search in Yahoo.  You may also be able to get a list of Urls from a webmaster console in Yahoo or Google.  This is the list of Urls you will redirect from.

Once you have a list of all the urls you need to capture and redirect, you need to have the new Urls to send them to.  It's often tempting to just redirect everything to the home page of your new site, but if you can, plan your new site so that it has logical places to send the old urls.  You should have at least rough categories like products -> new product page, contact -> new contact page, etc.

Make sure these new Urls are created in DNN so you can see the Urls you'll redirect to.

3. Map the relevant file extension to ASP.NET

This is the important part.  A little background : the extension on a request to your IIS webserver allows IIS to determine which piece of software installed on the webserver should handle the request.  If you request a .htm file, then IIS knows what to do with it : it just streams the file back out to the browser as is by reading it from the file system and sending it back out.  Same thing for Jpeg or Gif files : it sets the media type of the response, and then streams the binary image information back to the browser.  So far so good.  When your IIS server receives a response with the .aspx extension, it knows that it must pass that response to the ASP.NET software (called the ASP.NET runtime) installed on the server.  ASP.NET then handles the interpretation of the code within your .aspx file, and gives the results back to IIS, which ten steams them back to the requesting browser.  

There's nothing magic about the .aspx extension : Microsoft just decided on this because the previous generation of ASP used the .asp extension, and it needed a new one.  So they decided on .aspx and the rest is internet history.  The same principle applies to .axd, .ashx and all the other ASP.NET specific extensions.  All they do is inform IIS to pass the request along to ASP.NET for processing.

Now, DNN is just a program built using ASP.NET technology, so each and every request for DNN must be associated with the ASP.NET runtime files.  This is why the standard DNN Urls all end with /default.aspx : so that IIS knows that ASP.NET must be used to handle the request.

When you install the Url Master software, it gets run for each and every request that is handled by ASP.NET, and, by association, DotNetNuke.  If that sounds concerning to you, don't be worried, because the Url Master software has an efficient regex filter to ignore the requests it doesn't need to intercept.

Now, in order for the Url Master software to redirect your old .htm request to your new DNN page, it needs to know when that .htm request is made.  This is done by mapping the .htm extension to the ASP.NET runtime, so it behaves in just the same way as a .aspx page.

Concerned? You needn't be.  Although you can serve up html pages using the ASP.NET runtime, you won't even be doing that.  All that will be happening is that the .htm request will be intercepted by the Url Master software, it will decide where it should be redirected to, and the redirect will take place.  The whole redirect process is lightning fast.  And if you have a .htm page in your website that isn't a DNN url, then asp.net will just process it in the same way that IIS does - you, your server or your visitors won't be able to tell the difference.

Here's how you do that mapping:

IIS6

Go to your IIS Management page.

  • open the property page for website / virtual directory.
  • click the 'home directory' tab
  • click the 'configuration' button, select the 'mappings' tab
  • click 'Add' under the 'Application Extensions' list to add a new application extension mapping
  • browse to the aspnet_isapi.dll (normally at c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll)
  • Ensure that 'check that file exists' is unchecked
  • Click OK, OK, OK to close and apply changes

IIS7 Classic Mode / Integrated Pipeline mode

In IIS7 you can change the configuration in the web.config file, which saves having to mess about with the IIS user interface.  This is also very useful if your host doesn't give you direct access to your IIS interface.

What you need to do is specify a new handler for the .htm extension.  The entries below are separate : one for classic mode, one for integrated mode.  It's best just to enter both, in case you don't know if you're using classic or integrated, or if you decided to switch in the future.

<system.webserver>

<handlers>

<!-- classic mode .htm handler to make asp.net handle .htm requests -->

<add name="HtmlHandler-Classic" path="*.htm" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" />

<!-- integrated pipeline mode handler to make asp.net handle .htm requests -->
<add name="HtmlHandler-Integrated" path="*.htm" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" modules="ManagedPipelineHandler" requireAccess="Script" preCondition="integratedMode" />

</handlers>

</system.webserver>

These two entries inform IIS7 to run the related asp.net runtime when a .htm request is received.

4.  Configure ASP.NET to process .htm files

As previously mentioned, if you do have .htm files in your web application, then they are going to be processed by ASP.NET.  That's no problem, but you do need to let the ASP.NET runtime know about it. 

IIS6 / IIS7

First, tell ASP.NET how to handle .htm files by adding in a Http Handler

<system.web>
  <httpHandlers>    
    <add verb="*" path="*.htm" type="System.Web.UI.PageHandlerFactory" />
  </httpHandlers> 
</system.web>

Next, tell ASP.NET how to build a .htm file.  Note that nothing actually changes as there is no code in the file, but it still needs to be run through the build process.

<system.web>
  <compilation>    
    <buildProviders>
      <add extension=".htm" type="System.Web.Compilation.PageBuildProvider" />
    </buildProviders>
  </compilation> 
</system.web>

Remember that because the web.config file is an Xml file, all of this is case sensitive, so take care with all of your entries.

5.  Configure the Url Master software to stop ignoring .htm files.

This is done by expanding out the 'Advanced Regex Filters' section, and changing the value in the 'ignoreRegex'.  What you need to do is carefully remove the section relating to the .htm extension : it will look something like this: |\.htm$

Once this is done, the Url Master software will inspect all of the .htm requests for rewriting and allow it to perform a redirect if necessary.   Note that any time the Url Master module finds a physical file on the server relating to a request, it performs no rewriting.  In other words, if /myfiles/myfile.htm exists on the server, then the software knows that it's not a virtual Url, and therefore leaves it alone to continue processing.

Note : A virtual Url is a url that doesn't correspond to an actual file on your server.  A virtual Url is a 'made up' Url that doesn't work unless there is some software interpreting what the Url means.  That's the reason a 404 Resource Not Found error is quite common if your Url Rewriting isn't configured correctly.

6.  Add in your .htm redirects in the Url Master User Interface

To do this, go to the Admin->Page Urls page that is created when the Url Master software is installed.  In order to setup a redirect, you need to work backwards.  That is, you select the page you would like to redirect to, and enter the Url you'd like to redirect from.

htm_aspx_301_redirect_add

Remember to click the 'apply changes' button when you're finished.

7. Test and Check your Results

There's two ways of testing your redirects.  The first is to go to the Friendly Url Settings page, and use the 'Test Url Rewriting' section.  Type in the full Url as you want redirected, and click the 'test' function.

Redirect_htm_aspx_test

The above example shows the test output for 'oldpage.htm', which redirects to the DNN page called 'New Page' at new-page.aspx.

Wrapping Up

These instructions actually contain the advice for another, related task.  You can run your DNN site on whatever extension you like : from .aspx, to .htm, even .php or .dnn!  There is no restriction on what the page extension is for your site.  If you want to run your entire DNN site on a different page extension, just change the page extension in the Friendly Url Settings page, and ensure all the above ASP.NET mapping is in place before you hit the 'Apply Changes' button.

I once read someone on an ASP.NET support forum lecturing another person for wanting to change away from .aspx : the lecture took the form of 'why would you want to even do that?'.  Well, there are many reasons not to run the .aspx extension for your DNN pages : backwards compatibility, obfuscation of technology, lots of reasons.

If you have other extensions that you need to redirect from, then you just follow the instructions as listed, replacing .htm with whatever extension you're working with.

Success Stories

If you've redirect an old site over to a new DNN site using the advice listed here, let us all know about it!  Just post your success stories in the comments.  I always get a kick out of seeing the code in action, solving what was once unsolvable problems!

Tags:

16 comment(s) so far...

RE:How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

Great post Bruce and very timely, so if we need to redirect multiple page extensions (in IIS7) would each of the steps above require the addition of - path="*.htm,*.php" and extension=".htm,*.php" etc?

Cheers

By Adam on   Tuesday, June 23, 2009 9:01 PM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

@adam : yes is the answer. You would need to repeat the steps in the configuration for each of the extensions you wish to intercept.

By Bruce Chapman on   Tuesday, June 23, 2009 10:50 PM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

Well, I tried it and I can not get it to work. I am on a shared hosting plan Wiindows Server 2008. I did the web.config changes and the other setup items you listed. When I test it using Friendly URl Setting they resolve correctly excep one case, /default.htm gives error 404. When I try to browse the old url , such as www.apropos-business.com/company.htm I get error 404.

I also have an old privacy/htm page but the DNN privacy page does not show up in the list to map the old url. How do I map to the privacy page?

Overall this looks like an excellent product and I just need to get the htm problems fixed.

By John on   Wednesday, June 24, 2009 3:15 PM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

@john it's hard to say without looking through all of your changes, but if the rest of your site is still working OK, then it's probably in the association of the .htm with the asp.net runtime. I would double check your settings and perhaps ask your host if they can check them for you as well.

Unfortunately you can't redirect to the privacy page because it's a special type of Url in DNN. However, if you map the .htm extension to your site properly, it may work out OK for you anyway. I haven't tried that myself, but I would expect it to work.

By Bruce Chapman on   Wednesday, June 24, 2009 3:35 PM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

What will happen if the file does not exist and the request is not being processed by URL Master?

Example: I set up the host to give 404s to any file and file extension that doesn't exist. So if oldpage.htm doesn't exist on the server, the host redirects it to my 404 page before URL Master has a chance to process the request. Can I have it both ways were it will 301 redirect "oldpage.htm" and 404 "doesntexist.htm"?

By erik on   Wednesday, July 22, 2009 12:54 AM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

@erik if the page doesn't exist and there is no physical htm file, you'll get a 404 error for 'doesntexist.htm'. However, you would need to set up your host so that virtual urls on the .htm extension are allowed through.

By Bruce Chapman on   Wednesday, July 22, 2009 10:03 AM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

We recently moved our old website to DNN and had dozens of old html and shtml files. I've got them all 301 redirecting to our new DNN pages (with no file extension, by the way) and it's marvelous. Everyone's old bookmarks still work, old links still work - it's great.

By Jonathan on   Friday, July 31, 2009 9:42 AM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

Hey Bruce,

I tried to do this and here is what happened....

1) I made the changes to the web.config file and uploaded it. Then, went into URL Master and did the test on the .php pages. All test came back with the URL redirects that I was looking for. So, this seemed to work just fine. (at least it appeared to).

2) I am in a shared hosted environment with PowerDNN on IIS 6.0. When I had PowerDNN support make the appropriate changes above, all pages in my site that had an extension (all are .aspx) came back with the error - "The system cannot find the file specified. "

So, I had them change it back until I could troubleshoot further.

I think that I am close, but am missing something.

Any suggestions.


Thanks.

By browe68 on   Saturday, August 29, 2009 12:53 PM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

Hi, after I used added your tags lines to the Web.config for HTML pages, my aspnet_isapi works GREAT for HTML document.

But when I used the same method (above) on .JPG and .gif extension, it displayed a whole page of unrecognized symbols instead of graphics.

Although it sounds weird, I do need aspnet_isapi.dll for all my forms (.jpg, .gif, .exe, .doc) because I have a httpModule running before them to handle the BeforeRequest event to check the users who they are before displaying the pages(.aspx)/documents(non .aspx)!!

Is "System.Web.Compilation.PageBuildProvider" and "System.Web.UI.PageHandlerFactory" OK for anything including .exe, .JPEG and .gif ? Why doesn't your method work? Is something to do with MIME type?

Thanks,
L.

By Lena Ip on   Friday, November 13, 2009 2:28 AM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

@lena : I haven't tried doing this for other MIME types, but I'm guessing that's what the problem is. If you're getting the byte content of the file delivered as text (which is what funny symbols on apage is) then it's likely to be the MIME type. I'd have to research this to say for sure.

By Bruce Chapman on   Friday, November 13, 2009 12:14 PM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

Bruce : Just another thing (could be a hint to my question above, never know!) to tell you is
When I test all my security modules for BeginRequest on my localhost (the workstation server that comes with Visual Studio 2008), everything works SURPRISINGLY fine WITHOUT mapping of any type like I have to do for the public server. On localHost, right after executing of the httpModule, the context immediately return to the display of TEXT (if .txt) and graphics (if .gif/.jpg/.wmf) ! And I didn't do a thing to make it happen on localhost.

Do you think localhost has something that the real IIS 6 does not have?

(I'm almost tempted to install Visual Studio 2008 on that machine!)
L.

By Lena Ip on   Saturday, November 14, 2009 1:40 AM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

Referring to the previous problem, my Workstation is Windows XP v5.1 (Service Pack 2) and the Web Server is Windows Server 2003 v5.2 R2 (service pack 2) -- they are both using aspnet_isapi.dll of v2.0.50727

By Lena Ip on   Saturday, November 14, 2009 1:57 AM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

@lena localhost is just the dns address of an IIS server - that makes no difference. I would say it is a configuration difference between your two servers (workstation and server) that is causing the difference, rather than something different in the software.

By Bruce Chapman on   Saturday, November 14, 2009 3:21 AM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

Bruce:Thank-you for your response!Still a mystery why my PC's localHost doesn't need any aspnet_isapi config, but the Windows 2003 server (the WebServer) does. However, after a long battle, I decide to write my own handler and it works!
L.

By Lena Ip on   Wednesday, November 18, 2009 11:01 AM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

Can you tell me how to do the opposite. I'm trying to retain all my good search engine ranking on an aspx site that has been redesigned into htm. Please help.

By Lenora on   Saturday, February 06, 2010 10:39 AM

Re: How To : 301 Redirect .htm or .html pages to DotNetNuke .aspx pages

@Lenora : this advice is for users of DotNetNuke. If you've switched to using a .html site you'll need to setup 301 redirects for all of your Urls. You'll need to find out how to do this with the new technology you're using.

By Bruce on   Saturday, February 06, 2010 3:28 PM

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment   Cancel 
Bruce Chapman
Hi, I'm Bruce Chapman, and this is my blog. You'll find lots of information here - my thoughts about business and the internet, technical information, things I'm working on and the odd strange post or two.