WWW附加在URL托管ASP站点(即没有IIS访问)(Append www in URL for H

2019-08-17 03:38发布

我看到写的胡言乱语,我不明白了许多类似的问题:

  • 重定向非www网址到www使用的.htaccess
  • 重定向URL加www到www
  • 重定向非www到www网址
  • 重写URL以非WWW多个站点

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

基本上,如果有人类型“mydomain.com”到地址栏,我想它解析为“www.mydomain.com”当页面加载完毕。

编辑:这是一个托管的网站,所以我不能配置IIS服务器。

Answer 1:

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

现在,在web.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>

(或)进入这一个:

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


Answer 2:

这是怎样的一个有趣的解决方案。 我只是建议,因为你描述的限制。 这是更好地做在IIS或使用像其他的答案中的HTTP模块所提出的建议。 然而,这也将工作,它只是没有完成它一个很好的办法。

你可以把这段代码到你的页面初始化事件处理程序(或初始化处理您的母版页)。

If Request.RawUrl.StartsWith("http://mydomain") Then
  Response.Redirect(Request.RawUrl.Replace("://", "://www."))
End If

其中mydomain就像mydomain.com没有www

它检查如果URL没有WWW其中WWW“应该”。 如果它不存在,将用户重定向到一个版本的页面,在正确的位置WWW的。



文章来源: Append www in URL for Hosted ASP Site (i.e. no IIS access)
标签: asp.net html url