C# 使用web.config将网站重定向到带有www的url

C# 使用web.config将网站重定向到带有www的url,c#,asp.net,redirect,web-config,C#,Asp.net,Redirect,Web Config,我正在尝试使用web.config重定向 如果url是http://xyzsample.com我想将其重定向到http://www.xyzsample.com 我尝试了下面的代码 <rule name="Imported Rule 1-1" enabled="true" stopProcessing="true"> <match url="^(*.*)$" ignoreCase="true" />

我正在尝试使用web.config重定向

如果url是
http://xyzsample.com
我想将其重定向到
http://www.xyzsample.com

我尝试了下面的代码

<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>


但这不是重定向,它会导致
500内部服务器错误

请尝试以下代码。我以前用过这个

<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>

匹配项应为
*
。有关详细信息,请参阅。