【问题标题】:How can I redirect an IIS website to use www如何重定向 IIS 网站以使用 www
【发布时间】:2022-11-25 11:04:51
【问题描述】:

作为试图访问https://www.qa1.samplewebsite.org的用户

我想被重定向到https://qa1.samplewebsite.org

没有 www 的网站工作得很好,但是当附加 www 时,它说“无法访问该页面”

使用 url 重写 2 条规则但没有用

web.config部分如下:

<rewrite>
   <rules>                
     <rule name="Remove WWW" stopProcessing="true">   
     <match url="^(.*)$" />    
     <conditions> 
        <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />  
     </conditions>   
    <action type="Redirect" url="https://{C:1}/{R:0}" redirectType="Permanent" />
     </rule>
   </rules>
</rewrite>

【问题讨论】:

  • 编辑问题并显示当前状态。如果您的web.config 文件中已经有重写/重定向规则,请显示它们。

标签: asp.net .net iis


【解决方案1】:

如果想把www重定向到非www,可以参考这个规则:

<rule name="Remove WWW" stopProcessing="true">
   <match url="^(.*)$" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^(www.)(.*)$" />
      </conditions>
   <action type="Redirect" url="https://{C:2}/{R:0}" redirectType="Permanent" />
</rule>

【讨论】:

  • 我已经尝试了上面的配置,但它似乎没有用。
  • 我编辑了我的答案,将 {C:1} 更改为 {C:2},请重试。
猜你喜欢
  • 1970-01-01
  • 2020-04-12
  • 2014-07-19
  • 2020-12-09
  • 2021-12-03
  • 1970-01-01
  • 1970-01-01
  • 2010-11-27
  • 2017-05-07
相关资源
最近更新 更多