在托管ASP站点的URL中附加www(即没有IIS访问)

jp2*_*ode 2 html asp.net url

我看到很多类似的问题用胡言乱语写成,我不明白:

我想知道如何使用微软的技术做到这一点......或者只是向我解释其他人在谈论什么以及如何使用它们.

基本上,如果有人在地址栏中输入"mydomain.com",我希望它在页面加载完毕后解析为"www.mydomain.com".

编辑:这是一个托管网站,所以我无法配置IIS服务器.

cod*_*der 6

  1. 非www到www重定向
  2. www.yourdomainname.com/default.aspx到www.yourdomainname.com

现在在web.config中添加config标签

<system.webServer>
<rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^yourdomainname.com$" />
          </conditions>
          <action type="Redirect" url="http://www.yourdomainname.com/{R:0}" redirectType="Permanent" />
        </rule>

        <rule name="Default Document" stopProcessing="true">
          <match url="(.*?)/?default\.aspx$" />
          <action type="Redirect" url="{R:1}/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
Run Code Online (Sandbox Code Playgroud)

(或)选择这个:

<rewrite>
    <globalRules>
        <rule name="Redirects to www.domain.com" patternSyntax="ECMAScript" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAny">
                <add input="{HTTP_HOST}" pattern="^domain.*(com|net)$" />
                <add input="{HTTP_HOST}" pattern="^(www.)?mydomain2.(com|net)$" />
                <add input="{HTTP_HOST}" pattern="^www.domain.net$" />
            </conditions>
            <action type="Redirect" url="http://www.domain.com/{R:0}" />
        </rule>
    </globalRules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)