【问题标题】:How do I enforce www on an IIS hosted website?如何在 IIS 托管网站上强制执行 www?
【发布时间】:2016-05-27 00:46:18
【问题描述】:

我的网站托管在 IIS 上,我需要强制浏览器使用 www 前缀。

我已经安装了Url Rewrite Module,我的规则是:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
              <rule name="Add WWW" stopProcessing="true">
              <match url="^(.*)$" />
              <conditions>
                 <add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)$" />
              </conditions>
              <action type="Redirect" url="http://www.{C:0}{PATH_INFO}" redirectType="Permanent" />
           </rule>
        </rules>
    </rewrite>
</system.webServer>

来自IIS7 URL Rewrite - Add "www" prefix

但我不知道如何维护 ssl

【问题讨论】:

  • 欢迎使用 stackoverflow,如果我误解了您的情况或只是弄错了,请考虑accepting 的答案或提供一些反馈:-)

标签: iis url-rewrite-module


【解决方案1】:

您需要在输入中捕获协议:

<rule name="Enforce WWW" stopProcessing="true">
  <match url=".*" />
  <conditions>
    <add input="{CACHE_URL}" pattern="^(.+)://(?!www)(.*)" />
  </conditions>
  <action type="Redirect" url="{C:1}://www.{C:2}" redirectType="Permanent" />
</rule>

{C:1} 将包含协议,{C:2} 将包含您的域和其他任何内容。

(source)

【讨论】:

    猜你喜欢
    • 2017-05-06
    • 2015-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    • 2013-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多