RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
]]>
1.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^EXAMPLE.COM [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://WWW.EXAMPLE.COM/$1 [R,L]
2.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^EXAMPLE.COM [NC,OR]
RewriteCond %{HTTP_HOST} ^WWW.EXAMPLE.COM [NC]
RewriteRule ^(.*)$ https://WWW.EXAMPLE.COM/$1 [L,R=301,NC]
3.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^EXAMPLE.COM [OR]
RewriteCond %{REQUEST_URI} !^/en
RewriteRule ^(.*)$ https://WWW.EXAMPLE.COM/$1 [L,R=301,NC]
]]>
I don’t know what !^/en
is supposed to accomplish in #3. It has nothing to do with HTTP or port 80. It’s probably related to someone’s multi-language site.
However, Steve’s example does not accommodate www. in the request. (Does anyone still type that anyway?) It’ll be in some links anyway. I would modify one line in Steve’s example, the rest are good.
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
The ? makes the preceding (group) optional.
I noticed you dropped the backslashes in copying his example. You shouldn’t do that. Without the backslash, the dot could match anything. The backslash requires that only a dot match the dot. In a practical sense it would make little difference here. It’s a good practice when using regexp to do so. In other situations it can be a security risk to not do so.
]]>