【问题标题】:Redirect all URLs to contain 'www' prefix重定向所有 URL 以包含“www”前缀
【发布时间】:2018-06-13 06:21:08
【问题描述】:

我想重定向来自

的所有流量
https://url

https://www.url

如何编写重定向网址?:

<rewrite>
            <rules>
                <rule name="Add www prefix">
                     <match url="(.*)" ignoreCase="true" />
                     <action type="Redirect" url="what to put here?" redirectType="Permanent" />
                   </rule>
            </rules>
        </rewrite>

【问题讨论】:

    标签: url redirect iis web-config url-redirection


    【解决方案1】:

    试试这样的:

    <rules>
       <rule name="www redirect" stopProcessing="true">
           <match url="(.*)" />
           <conditions>
             <add input="{HTTP_HOST}" pattern="off" ignoreCase="true" />
           </conditions>
           <action type="Redirect" redirectType="Found" url="https://www.{HTTP_HOST}/{R:1}" />
      </rule>
    </rules>   
    

    根据您的需要调整它,但我认为它有效。

    【讨论】:

      【解决方案2】:

      你有没有尝试过这样做

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration>
          <system.webServer>
              <rewrite>
                  <rules>
                      <rule name="Add www" patternSyntax="Wildcard" stopProcessing="true">
                          <match url="*" />
                          <conditions>
                              <add input="{HTTP_HOST}" pattern="www.YOURWEBSITE.com" negate="true" />
                          </conditions>
                          <action type="Redirect" url="http://www.YOURWEBSITE.com/{R:1}" />
                      </rule>
                  </rules>
              </rewrite>
          </system.webServer>
      </configuration>

      你可以找到更多here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-14
        • 2011-01-13
        相关资源
        最近更新 更多