2017-05-05 61 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

我已經改變規則請嘗試 –