【问题标题】:redirect website to url with www using web.config使用 web.config 将网站重定向到带有 www 的 url
【发布时间】:2015-09-11 14:33:28
【问题描述】:

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

如果网址是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 internal server error

【问题讨论】:

  • 匹配应该是.*。详情请见here。

标签: c# asp.net redirect web-config


【解决方案1】:

试试下面的代码。我以前用过这个

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-03-04
    • 2018-03-31
    • 1970-01-01
    • 2017-03-30
    • 1970-01-01
    • 2017-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多