【发布时间】:2017-07-31 17:26:40
【问题描述】:
我浏览了许多论坛并尝试了许多解决方案。没有一个可以正常工作。我正在为 IIS 使用 ISAPI Rewrite 3。
我需要将对我们网站的所有请求更改为 WWW 和 HTTPS。
例如:
- https://example.com/a-page-here/
- http://example.com/a-page-here/
- http://www.example.com/a-page-here/
- www.example.com/a-page-here/
- example.com/a-page-here/
全部改为:
我使用了http://htaccess.madewithlove.be,这可能是错误的,因为对于所谓的工作解决方案,我得到了看似不正确的结果。我不想在现场测试大量的东西。
我发现的这个所谓正确的例子(其中之一)给出了错误的结果:
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !443
# Extract non-www portion of HTTP_HOST
RewriteCond %{HTTP_HOST} ^(www\.)?(.*) [NC]
# Redirect to HTTPS with www
RewriteRule (.*) https://www.%2/$1 [R=301]
示例测试:
- example.com/a-page-here/ = https://www./example.com/a-page-here
- www.example.com/a-page-here/ = https://www./www.example.com/a-page-here/
谁能给我一套规则,将任何非 www 请求干净可靠地转换为正确的 https://www 版本,并且不添加无效的斜杠等?
【问题讨论】:
标签: iis https url-rewriting isapi-rewrite