【问题标题】:Windows Azure: redirect website from www to non-wwwWindows Azure:将网站从 www 重定向到非 www
【发布时间】:2015-04-29 16:56:06
【问题描述】:

我的服务器上有这个web.config 文件。

<rewrite>
   <rules>

      <rule name="HTTP to HTTPS redirect" stopProcessing="true">
         <match url="(.*)" />
         <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
         </conditions>
         <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
      </rule>

      <rule name="Rule" stopProcessing="true">
         <match url="^(.*)$" ignoreCase="false" />
         <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
         </conditions>
         <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
      </rule>

   </rules>
</rewrite>

我想将 URL 从 www 重定向到非 www。例如,如果用户输入www.exmaple.com,它应该转到https://example.com

如何在上面的代码中编辑这样的东西。谢谢。

【问题讨论】:

  • 为什么要包含php.htaccess 标签?您想要对您的规则进行 htaccess 翻译,还是只需要 IIS 的规则?
  • 不.. 只是 II.. 让我删除那些

标签: redirect azure iis web-config rewrite


【解决方案1】:

您可以这样(我已将 https/非 www 规则合并到一个规则中)

<rule name="HTTPS and non-WWW only" stopProcessing="true">
    <match url="^(.*)$" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        <add input="{HTTP_HOST}" pattern="^www\." ignoreCase="true" />
    </conditions>
    <action type="Redirect" redirectType="Found" url="https://example.com/{R:1}" />
</rule>

<rule name="Generic default rule" stopProcessing="true">
    <match url="^(.*)$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/favicon\.ico$" ignoreCase="true" negate="true" />
    </conditions>
    <action type="Rewrite" url="/index.php/{R:1}" appendQueryString="true" />
</rule>

【讨论】:

  • 不是从 www 重定向到非 www。
  • 抱歉,我使用了AND 条件而不是OR。你可以用我编辑的代码再试一次
  • 哇。完美的。太感谢了。你解决了我最大的问题
  • 完美!尝试了许多其他在互联网上找到的解决方案,但都没有成功,但这一个效果很好!谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-12
  • 2020-12-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多