Friday 23 September 2011

How to redirect in web.config

Let's say you want to redirect visitors from one subdomain to another. You can do this by putting this in your web.config for the redirected-from application:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpRedirect enabled="true" destination="https://abc.example.com/newpages" httpResponseStatus="Permanent" />
    </system.webServer>
</configuration>

This is ideal for obsolete website addresses that may still be saved in favorites, or linked to on a corporate intranet, or for redirecting common mistakes, such as users entering www.example.com/webmail when what they really want is mail.example.com/webmail.