简体   繁体   中英

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM