从www重定向到非www web.config asp.net

时间:2018-06-21 20:41:35

标签: asp.net web-config

我很难用web.config创建一个简单的重定向。我认为这将和htaccess一样简单。

这是我正在写入web.config的内容,但它会将网站分为500个错误。

<system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to non-www" stopProcessing="true">
          <match url="(.*)" negate="false"></match>
          <action type="Redirect" url="https://yourdomain.com/{R:1}"></action>
          <conditions>
            <add input="{HTTP_HOST}" pattern="^yourdomain\.com$" negate="true"></add>
          </conditions>
        </rule>
      </rules>
    </rewrite>
    <modules runAllManagedModulesForAllRequests="true"> 
      <add name="Migration" type="Migration" preCondition="managedHandler" />
    </modules> 
    <validation validateIntegratedModeConfiguration="false" />
    <httpErrors> 
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="/default.aspx" responseMode="ExecuteURL" />
    </httpErrors>
  </system.webServer>

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

解决了使用来自AWS的S3的问题,从那里轻松创建301不需要编码。