【发布时间】:2018-05-04 02:19:49
【问题描述】:
我正在尝试强制任何常规 http 请求重定向到 https,并且还强制 URL 中的非 www,以便最终每个请求都是 https://example.com
http://example.com 变为 https://example.com
http://www.example.com 变为 https://example.com
https://www.example.com 变为 https://example.com
http://example.com 变为 https://example.com
我的 htaccess 文件中有以下代码。
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
但我收到一个错误,指出它有太多重定向。它似乎在这个测试站点上工作正常,输出正确:
对此有何想法或更好的方法?
【问题讨论】:
-
@anubhava 它显示 example.com 并说(失败)net::ERR_TOO_MANY_REDIRECTS
-
使用命令行
curl运行这个命令curl -ILk 'http://example.com'并发布它的输出。
标签: apache .htaccess redirect mod-rewrite