2017-05-05 62 views
0

我有这样的重写规则:IIS URL从非www重定向到www不工作

<rewrite> 
    <rules> 
    <rule name="Force non-WWW and SSL" enabled="true" stopProcessing="true"> 
     <match url="(.*)" /> 
     <conditions logicalGrouping="MatchAny"> 
     <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" /> 
     <add input="{HTTPS}" pattern="off" /> 
     </conditions> 
     <action type="Redirect" url="https://www.yourdomainname.com/{R:1}" appendQueryString="true" redirectType="Permanent" /> 
    </rule> 
    </rules> 
</rewrite> 

它成功地重定向example.comhttps://example.com,但是,我需要重定向https://www.example.com,我怎样才能做到这一点?

回答

0

试试这个,只是限制域名或者你想要动态域名?

<rewrite> 
     <rules> 
     <rule name="Force non-WWW and SSL" enabled="true" stopProcessing="true"> 
      <match url="(.*)" /> 
      <conditions logicalGrouping="MatchAll"> 
      <add input="{HTTPS}" pattern="off" ignoreCase="true" /> 
      <add input="{HTTP_HOST}" negate="true" pattern="^www.(.*)$" ignoreCase="true" /> 
      </conditions> 
      <action type="Redirect" url="https://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" /> 
     </rule> 
     </rules> 
    </rewrite>  

使用所有的比赛和否定重定向

+0

是的,我也想动态域名了。您的规则是否可以使用https重定向? –

+0

你还希望如果没有www追加? –

+0

我已经改变规则请尝试 –