繁体   English   中英

想用 www 打开我的网站

[英]Want to Open My Website with www

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

这需要在 web.config 中完成,而不是 .htaccess。 有一个类似的问题,在这里得到了很好的回应。

为此,您可以使用IIS URL 重写模块 但是默认情况下它没有安装在服务器上。 安装后,您可以在站点的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>

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM