通过 htaccess 强制非 www 和 https [英] Force non-www and https via htaccess

查看:28
本文介绍了通过 htaccess 强制非 www 和 https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图强制用户重定向到非 www 网站,并强制使用 https.

I'm trying to force a user to be redirected to the non-www website, and, force https.

我已经完成了这种工作,但在输入 http 时不会强制使用 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?

推荐答案

试试这个规则:

RewriteCond %{HTTP_HOST} ^(www.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]

这篇关于通过 htaccess 强制非 www 和 https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆