2013-02-25 73 views
0

我用URL重寫在IIS管理器節創建我的網站redirect 301和重定向搜索引擎和用戶DomainName.comwww.DomainName.com。爲此,在IIS中創建規則後,它會生成以下代碼web.config文件:創建301重定向在Windows Server

<rewrite> 
    <rules> 
     <rule name="redirect 301" stopProcessing="true"> 
      <match url="^DomainName\.com.*" /> 
      <action type="Redirect" url="www.{R:0}" /> 
     </rule> 
    </rules> 
</rewrite> 

,但它不爲我工作。

在我的代碼中是否有任何錯誤,或者我必須使用另一種方法來做到這一點?

回答

0

我發現我的答案Scott Guthrie post:場景4:正規主機名, 爲了這個目的,我必須創建canonical domain name規則和寫我的主URL重定向到其他形式的網址連到的。 和web.config文件中的代碼是這樣的:

<rewrite> 
    <rules> 
     <rule name="CanonicalHostNameRule1"> 
      <match url="(.*)" /> 
      <conditions> 
       <add input="{HTTP_HOST}" pattern="^www\.domainName\.com$" negate="true" /> 
      </conditions> 
      <action type="Redirect" url="http://www.domainName.com/{R:1}" /> 
     </rule> 
    </rules> 
</rewrite>