Redirect 如何将所有流量重定向到https&;web.config中的非www?

Redirect 如何将所有流量重定向到https&;web.config中的非www?,redirect,iis,web-config,Redirect,Iis,Web Config,我正在使用SSL证书和IIS。在my web.config中,我希望按照以下顺序重定向所有网站流量: 所有http-->https 所有www-->非www 您希望使用来执行此操作。这会在请求进入服务器时拦截请求,并根据您的指示对其进行更改 以下是将所有内容重定向到https的操作: <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryStrin

我正在使用SSL证书和IIS。在my web.config中,我希望按照以下顺序重定向所有网站流量:

  • 所有http-->https
  • 所有www-->非www
  • 您希望使用来执行此操作。这会在请求进入服务器时拦截请求,并根据您的指示对其进行更改

    以下是将所有内容重定向到https的操作:

    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
    
    
    
    下面是一个将www重定向到非www的方法:

    <conditions> <add input=”{HTTP_HOST}” pattern=”^example\.com$” negate=”true” /> </conditions> <action type=”Redirect” url=”http://example.com/{R:1}” />
    
    
    
    当您在搜索中同时包含“web.config”和“redirect”时,web和StackOverflow上有很多文章

    确保在设置规则时,只对最终规则使用
    stoppprocessing=“true”
    。如果这出现在第一条规则上,那么第二条规则将永远不会执行。

    我找到了答案

     <system.webServer>
    
    
      <rewrite>
       <rules>
         <clear />
    
         <rule name="NonWwwRedirect"  stopProcessing="true"> 
        <match url="(.*)" /> 
        <conditions> 
            <add input="{HTTP_HOST}" pattern="^www.yoursit\.com$" /> 
        </conditions> 
        <action type="Redirect" url="http://yoursite.com/{R:1}" /> 
    </rule> 
         <rule name="Redirect to https" stopProcessing="true">
           <match url=".*" />
           <conditions>
             <add input="{HTTPS}" pattern="off" ignoreCase="true" />
           </conditions>
           <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
         </rule>
       </rules>
     </rewrite>
     <system.webServer />
    
    
    
    请指定您正在使用的web服务器我需要两个条件,请帮助