Vignesh Subramanian
Vignesh Subramanian

Reputation: 7289

redirect website to url with www using web.config

I am trying to redirect using web.config

if the url is http://xyzsample.com I want to redirect it to http://www.xyzsample.com

I tried the below code

<rule name="Imported Rule 1-1" enabled="true" stopProcessing="true">
                    <match url="^(*.*)$" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTP_HOST}" pattern="xyzsample.com" />
                    </conditions>
                    <action type="Redirect" url="http://www.xyzsample.com/{R:1}" redirectType="Permanent" />
                </rule>

But this is not redirecting and its causing 500 internal server error

Upvotes: 1

Views: 365

Answers (1)

Sithu05
Sithu05

Reputation: 146

Try the below code. I have used this before

<rewrite>
    <rules>
        <rule name="Redirect to non-www" stopProcessing="true">
            <match url="(.*)" negate="false"></match>
            <action type="Redirect" url="http://domain.com/{R:1}"></action>
            <conditions>
                <add input="{HTTP_HOST}" pattern="^domain\.com$" negate="true"></add>
            </conditions>
        </rule>
    </rules>
</rewrite>

Upvotes: 2

Related Questions