Redirect Windows Azure:将网站从www重定向到非www

Redirect Windows Azure:将网站从www重定向到非www,redirect,azure,iis,web-config,rewrite,Redirect,Azure,Iis,Web Config,Rewrite,我的服务器上有这个web.config文件 <rewrite> <rules> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCas

我的服务器上有这个
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

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

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



为什么要包含
php
.htaccess
标记?您想要规则的htaccess翻译还是只需要IIS的规则?否。。只有IIs。。让我删除这些内容,因为它没有从www重定向到非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>