Apache Mod Rewrite all incoming urls to https://www
<p>I want to redirect all incoming urls to my website to a single url for canonicalization purposes.</p>

<p>Following redirect conditions should meet</p>

<ol>
<li><a href="http://example.com-" rel="nofollow">http://example.com-</a>> <a href="https://www.example.com" rel="nofollow">https://www.example.com</a></li>
<li><a href="http://www.example.com" rel="nofollow">http://www.example.com</a> -> <a href="https://www.example.com" rel="nofollow">https://www.example.com</a></li>
<li><a href="https://example.com" rel="nofollow">https://example.com</a> -> <a href="https://www.example.com" rel="nofollow">https://www.example.com</a></li>
<li>www.example.com -> <a href="https://www.example.com" rel="nofollow">https://www.example.com</a></li>
</ol>

<p>My current Rewrite rules written in httpd.conf look as follows</p>

<pre><code>RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]
</code></pre>

<p>With the above rules I am able to achieve 1st,2nd and 4th rule but 3rd doesn't work for me.
Any suggestions are welcome.</p>