问题描述
我最近获得了我的网站的SSL证书,并希望将所有流量重定向到HTTPS。我有一切要去 https://mydomain.com
,但如果有人输入 http://mydomain.com/anotherpage
它删除了另一页,只是将用户带到主页。
I recently got a SSL certificate for my website and want to redirect all traffic to HTTPS. I got everything to go to https://mydomain.com
but if someone enters http://mydomain.com/anotherpage
it drops the other page and just takes the user to the home page.
我的 web.config中的规则
文件如下所示:
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
我也试过 https:// {HTTP_HOST} {REQUEST_URI}
没有任何成功。任何人都可以告诉我我需要做什么才能使网站重定向到正确的HTTPS版本的页面?我觉得它与模式有关,但我似乎无法弄清楚语法。
I also tried https://{HTTP_HOST}{REQUEST_URI}
without any success. Can anyone tell me what I need to do to make the website redirect to the proper HTTPS version of the page? I have a feeling it has something to do with the pattern, but I can't seem to figure out the syntax.
推荐答案
我找到了一种方法,你不需要重写模块。
以下适用于Windows 8(IIS 8.5):
I found a way to do this, and you don't need the Rewrite module for it.
The following worked for me on Windows 8 (IIS 8.5):
- 从您的网站删除HTTP绑定(保留HTTPS)
- 添加其他网站
- 确保新网站具有HTTP绑定
- 配置HTTP重定向,如下所示:
- Remove the HTTP binding from your site (leave HTTPS in place)
- Add another site
- Make sure that the new site has HTTP binding
- Configure HTTP Redirect as shown:
现在所有HTTP请求都将重定向到您的HTTPS网站并保留网址的其余部分。
Now all HTTP request will redirect to your HTTPS site and will preserve the rest of the URL.
这篇关于IIS HTTP到HTTPS相对重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!