通过 htaccess 强制使用非 www 和 https
我试图强制用户重定向到非 www 网站,并强制使用 https。
我已经完成了这种工作,但在输入 http 时不会强制使用 https。
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://site.com\.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
关于我做错了什么有什么想法吗?
I'm trying to force a user to be redirected to the non-www website, and, force https.
I've got this which sort of work, but doesn't force https, when http is entered.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://site.com\.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Any ideas on what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个规则:
Try this rule:
根据 Gumbo 的评论:“在将 TLS/SSL 连接传递给 HTTP 并进行 HTTP 重定向之前,已建立 TLS/SSL 连接并验证证书”
我尝试了一下(似乎有效):
请告诉我这种方法是否有问题。
Based on Gumbo's comment : "the TLS/SSL connection is established and certificate is validated before it is handed down to HTTP and the HTTP redirection takes place"
I gave this a try (which seems to work):
please tell me if there is something wrong with this approach.
对我有用的唯一一组规则是以下
顺序很重要,它在某些情况下可以防止第三次重定向。
The only set of rules that works for me is the following
The order matters, it prevents a third redirect in some cases.
使用此代码,我从 http and www and none www 重定向到 https none www。请注意,在 htaccess 中插入代码的位置很重要:
With this code I rediret from http and www and none www to https none www. Just pay attenstion that the place you insert the code in htaccess is important: