How to redirect domains, sub-domains, and website pointers using URL rewrite
Posted by on 21 December 2012 09:00 AM

The following rewrite rule redirects requests to domain pointers of a Web site to the Web site's URL. This is required to rewrite the URL in the address bar of the browser requesting the domain pointers. The rule preserves the sub-domain requested and the document path.

<rewrite>
    <rules>
    ...

        <rule name="Redirect domain pointers to example.com" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
                <add input="{HTTP_HOST}" pattern="example\.com$" negate="true" />
                <add input="{HTTP_HOST}" pattern="^((.*\.)?).*\.com$" />
            </conditions>
            <action type="Redirect" url="http://{C:1}example.com/{R:1}" redirectType="Permanent" />
        </rule>

    ...
    </rules>
</rewrite>


Usage:
Replace the tokens 'example' and 'com' as required and copy and paste the rewrite rule to the <system.webServer> section of the Web site's Web.config file.


Examples:
Request to example.net (domain pointer) resolves to example.com (Web site).
Request to example.net/path (domain pointer/path) resolves to example.com/path (Web site/path).
Request to sub.example.net (sub-domain.domain pointer) resolves to sub.example.com (sub-domain.Web site).
Request to sub.example.net/path (sub-domain.domain pointer/path) resolves to sub.example.com/path (sub-domain.Web site/path).

(6 vote(s))
Helpful
Not helpful

Comments (2)
Joao Nunes
01 July 2015 07:27 AM
hi Adam, how would I redirect www.gourmetcheesecake.ie to www.theartisancentre.com/vendors/gourmet-cheesecake?
Ryan C
06 July 2015 10:14 PM
Please reach out to our support team for assistance with getting a rewrite rule added if you are struggling with this.
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).