URL 重写 从 HTTPS 中删除 WWW [英] URL Rewrite Remove WWW From HTTPS

查看:20
本文介绍了URL 重写 从 HTTPS 中删除 WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 IIS8 上的 URL Rewrite 中设置一个规则,以从所有 https 请求中删除 www.

I need to set up a rule in URL Rewrite on IIS8 to remove the www from all https requests.

以下是我想要实现的目标.我不在乎我们是否从所有网址中删除 www.

Below is what I want to achieve. I do not care if we remove www from all urls.

http://sitename.com/sub        ->    http://sitename.com/sub
http://www.sitename.com/sub    ->    http://www.sitename.com/sub

https://sitename.com/sub       ->    https://sitename.com/sub
https://www.sitename.com/sub   ->    https://sitename.com/sub

推荐答案

我让它与这条规则一起工作.

I got it to work with this rule.

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

我还在它上面添加了这个规则来强制所有请求到 https

I also added this rule above it to force all requests to https

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
   <match url="(.*)" />
   <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
   </conditions>
   <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>

这篇关于URL 重写 从 HTTPS 中删除 WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆