Blogs‎ > ‎

Replicating 301 Redirects and other configs from IIS downlevel versions

posted 2 Jul 2015, 14:58 by Andrew at Lycom   [ updated 2 Jul 2015, 14:59 ]
So, while migrating a web site currently on an IIS6 Windows 2003 Server to an IIS 7.5 Windows 2008 R2 Server, it had lots of things like re-directs I needed to move across.  How to do this without spending hours on it? Well, first I exported the config of the original site with  'All tasks / Save Configuration to a File' and got a nice dump of all the settings.

Some of those were just prompts to make the appropriate changes in the IIS 7 admin console - handy, especially as you are unlikely to know / remember all the configuration customisations made to a website.

But others, like the 301 redirects (Nearly 40x) would take an age to do via the GUI. So, with a bit of mangling with the excellent Notepad++ editor  I was able to create 40x web.config files with the redirect statements in:

<?xml version="1.0" encoding="UTF-8"?>
        <httpRedirect enabled="true" destination="" httpResponseStatus="Permanent" />

As each directory didn't have an existing web.config, I was able to drop these new web.config files into the appropriate directory and then test to make sure the re-directions were working perfectly.

There is an alternative method if you have a Plesk control panel:

Create an .htaccess file in the website root

edit it as follows:

redirect 301 /
redirect 301 /oldpage/
redirect 301 /oldpage.html

It worked for some, but not for all - particularly where the directory had no content and I got the 'no directory browsing' error. I'm sure it's solvable, but I think the web.config method is more robust in IIS so I stuck with that one.