【问题标题】:Want to Open My Website with www想用 www 打开我的网站
【发布时间】:2017-06-29 22:55:41
【问题描述】:

我有任何 asp.net mvc 网站,我想将其打开为 www.example.com 而不是 example.com。我想将每个使用example.com 的用户重定向到www.example.com。我这样做的原因是为了维护 cookie。目前有 2 个不同的 cookie 集,一个适用于 www.example.com,另一个适用于 example.com。我该怎么做?

【问题讨论】:

  • 我认为您需要查看 .htaccess 重定向
  • 你为什么不直接为.example.com设置cookie?

标签: c# asp.net cookies url-rewriting


【解决方案1】:

您可以为此使用IIS URL Rewrite Module。但默认情况下它没有安装在服务器上。安装后,您可以在站点的 Web.Config 文件中创建规则。

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

【讨论】:

    【解决方案2】:

    这需要在 web.config 中完成,而不是在 .htaccess 中。有一个类似的问题,回复很好here

    【讨论】:

      【解决方案3】:

      您可以在 DNS 甚至 IIS 设置中配置从 example.com -> www.example.com 的重定向。

      【讨论】:

        猜你喜欢
        • 2023-03-30
        • 1970-01-01
        • 2020-07-21
        • 1970-01-01
        • 2018-05-09
        • 1970-01-01
        • 2011-05-01
        • 1970-01-01
        • 2017-11-04
        相关资源
        最近更新 更多