2010-09-02 157 views
1

我想写IIS7 URL重写是做两件事情的规则:多IIS7 URL重写规则

  • 如果请求是对HTTP,它强制HTTPS
  • 如果url有一个“WWW “在里面,删除它,然后重定向到不同的URL

在这两种情况下,我想重定向到https://my.domain.com(替代真实的域名)

我与HTTP到HTTPS规则没有问题。此外,http://www.my.domain.comhttps://my.domain.com的情况也适用。然而,在一个情况下,我一直没能得到工作是当原来的请求是https://www.my.domain.com

这是我现在有:

<rule name="r2" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions logicalGrouping="MatchAll"> 
    <add input="{SERVER_PORT}" pattern="443" negate="false" matchType="Pattern" /> 
    <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" matchType="Pattern" />   
    </conditions> 
    <action type="Redirect" url="https://my.domain.com" /> 
</rule> 

<rule name="r1" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions logicalGrouping="MatchAll"> 
    <add input="{SERVER_PORT}" pattern="443" negate="true" matchType="Pattern" /> 
    <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" matchType="Pattern" /> 
    </conditions> 
    <action type="Redirect" url="https://my.domain.com" /> 
</rule> 

什么,我需要改变任何主意,让https://www.my.domain.com重定向到https://my.domain.com

回答

0

这可能会为你

<rule name="Canonical Host Name" stopProcessing="true"> 
    <match url="(.*)"/> 
    <conditions> 
    <add input="{HTTP_HOST}" pattern="https://mydomain.com$"/> 
    </conditions> 
    <action type="Redirect" url="https://www.mydomain.com/{R:1}" redirectType="Permanent"/> 
</rule> 
0

工作试试这个它是为我工作

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <rewrite> 
      <rules> 
       <rule name="permalink"> 
        <match url="article/(\D+)(\/)*$" /> 
        <action type="Rewrite" url="http://mywebsite.com/article.aspx?id={R:1}" /> 
       </rule> 
      </rules> 
     </rewrite> 
    </system.webServer> 
</configuration>