简体   繁体   中英

Redirect from www to non-www web.config asp.net

I am having a hard time with web.config to create a simple redirection. I thought it would be as simple as htaccess.

This is what I am writing into web.config but it breaks the site into 500 error.

<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>

What am I doing wrong here?

修复了使用来自AWS的S3的问题,从那里轻松创建301且无需编写代码就可以了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM