Apache 2.4: htaccess forwarding to https and removing www
<p>I'm having a weird problem with an htaccess (Apache version 2.4). I am using the folliwing code:</p>

<pre><code>RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_PORT} !^443$ [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
</code></pre>

<p>to force the following redirects:</p>

<ul>
<li>http should become https in general</li>
<li>any www. should be removed</li>
</ul>

<p>As it's a TYPO3 installation, I'm having a domain record inserted at the entry page, but it does not have any redirects whatsoever. So any redirecting is/should be done by the .htaccess file.</p>

<p>However, here is the problem:</p>

<ul>
<li>http + example.com gets forwarded to https + example.com</li>
<li>https + example.com stays the same</li>
<li>http + www + example.com gets forwarded to https + example.com</li>
<li><strong>https + www + example.com stays the same, instead of forwarding to http + example.com</strong></li>
</ul>

<p>Does anybody have any idea what could be wrong with the code in the .htaccess file?
The problem is that if a user uses <a href="https://www.example.com/" rel="nofollow">https://www.example.com/</a>, he gets an annoying certificate issue warning. But as I understand the code, it should forward if either there is no https or if the domain is not "example.com", e.g. "www.example.com", so basically, it should work, no?</p>

<p>Thanks in advance,
Thomas</p>