htaccess 将 HTTP 和 HTTPS 非 www 重定向到 HTTPS www

Sub*_*oFX 0 mod-rewrite .htaccess redirect

如何将我的网站从所有 HTTP 请求重定向到 HTTPS,并将非 www HTTPS 重定向到带有 www 的 HTTPS?

例子:

重定向 HTTP 非 www、HTTP www。& HTTPS 非 www:

HTTP://example.com/&& HTTP://www.example.com/&&HTTPS://example.com/

带有 www. 的 HTTPS 的所有内容:

HTTPS://www.example.com/

小智 5

# Redirect all "not correct" domain to www with https
# (is not important if comes with or without https):
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

# Redirect all non-ssl to ssl.
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Run Code Online (Sandbox Code Playgroud)

我认为这将适用于您的实际规则。