URL Rewrite Remove WWW From HTTPS

谁说我不能喝 提交于 2019-11-30 18:56:30

问题


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

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

回答1:


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>

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>


来源:https://stackoverflow.com/questions/22385563/url-rewrite-remove-www-from-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!