不带www跳转www301重定向

时间:2025-07-09 17:24:54  阅读量:  分类:标签:

web.config ,放在网站根目录

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to www" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^example\.com$" />
          </conditions>
          <action type="Redirect" url="https://www.example.com/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>