Redirect Old Website Domain to New Domain Keeping Folder Path Structure with Web.Config

Redirect Old Website Domain to New Domain Keeping Folder Path Structure with Web.Config

Apologies for the obscenely long post title but I wanted to make sure I got all the keywords in that people might search for.  Why you may ask?  Well because I had a hell of a time getting an answer to arguably the single simplest form of URL Redirection you could possibly want to do:

Redirect Everything

The catch was that I wanted to redirect all traffic from my old domain name, to my new domain name, passing along the full folder structure as a 301 redirect (to pass on any search engine ‘good will’ to my new domain name).

So without further ado, here’s the code to put in to your web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
 <rule name="Redirect to New Domain Name" stopProcessing="true">
 <match url="(.*)" />
 <action type="Redirect" url="http://newdomain.co.uk/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

For anyone looking to get in to ASP web development I’d recommend Beginning ASP.NET 4.5 (C# and VB) and for you IIS server admins out there, have one of these on your desk!: IIS 7.0 Administrator’s Pocket Consultant

Bob McKay

About Bob McKay

Bob McKay works at Perfect Image, is a father, programmer and a self confessed techie-geek type.

Disclosure Policy

Bob on Google+

Leave a Reply

Your email address will not be published. Required fields are marked *