2015-09-11 30 views
1

我想使用的web.config重定向網站使用的web.config

如果URL http://xyzsample.com我想它重定向到http://www.xyzsample.com

重定向與WWW網址我試過下面的代碼

<rule name="Imported Rule 1-1" enabled="true" stopProcessing="true"> 
        <match url="^(*.*)$" ignoreCase="true" /> 
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
         <add input="{HTTP_HOST}" pattern="xyzsample.com" /> 
        </conditions> 
        <action type="Redirect" url="http://www.xyzsample.com/{R:1}" redirectType="Permanent" /> 
       </rule> 

但這不是重定向及其造成500 internal server error

+0

這個匹配應該是'。*'。有關詳細信息,請參閱[此處](http://weblogs.asp.net/owscott/iis-url-rewrite-rewriting-non-www-to-www)。 –

回答

2

嘗試下面的代碼。我以前用過這個

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