.htaccess将http://使用和不使用www和https:// www重定向到https:// non-www

Pau*_*ner 5 .htaccess mod-rewrite

我想重定向所有:

http://
http://www.
https://www.

to https://
Run Code Online (Sandbox Code Playgroud)

这可能在此之前已经得到了解答,但是经历了似乎相关的问题,他们都不是我所追求的,我尝试的一切都导致了重定向循环或者没有按照希望工作.

例如:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

RewriteCond %{HTTPS_HOST} ^example.com
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的帮助.

Jon*_*Lin 4

尝试:

RewriteCond %{HTTP_HOST} !^energenie4u\.co\.uk$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://energenie4u.co.uk/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)