user1082693
user1082693

Reputation: 621

Configure redirect asp.net/iis7

I have a website that opens when the user enters either http://example.com or http://www.example.com.

I need to configure the server or the app to redirect with a permanent redirect to www.example.com when example.com is accessed.

What is very important is that the path is preserved, so if example.com/path/page.aspx?p=1, the redirect should be done to www.example.com/path/page.aspx?p=1.

thanks!

Upvotes: 1

Views: 142

Answers (2)

Franze Caminha
Franze Caminha

Reputation: 141

Using the URL Rewrite you can do this by adding a configuration in you web.config. You need to install this module in your IIS as well. Here is an example, not fully tested:

<system.webserver>
<rewrite>
        <rules>               
            <rule name="Redirecting" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP}" pattern="^(http://)?example.com" ignoreCase="true" />
                </conditions>
                <action type="Redirect" redirectType="Permanent" url="http://www.example.com/{R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webserver>

Upvotes: 1

Darren Lewis
Darren Lewis

Reputation: 8488

The URL Rewrite module should do exactly what you need.

Upvotes: 1

Related Questions