Yes please, let's stay away of convoluted and most
times innecessary mod_rewrite examples to do simpleton
configurations.
If you are in virtualhost 80, you have specified servername
correctly and you just want to redirect to ssl, why not a
single Redirect statement?
As Yann's refered document says:
Most people here knows this but there are gazillions web
pages refering to bad advice, duck and tape solutions and
convolued ways of using mod_rewrite for a simple redirection
when placed in proper context, we need to finish with that
trend, and the best way is to give simple, straight to the
point examples "first".
The mod_rewrite example given,lets slice it out:
This clearly assumes it is a generic recipe in a .htaccess
somewhere which can be read from a non-SSL virtualhost or
non-SSL virtualhost (just to be ignored).
1º It checks the host name, but why? if you have defined
a VirtualHost with that servername and there are no
conflicts the request is already landing there.
2º It checks for port 80. But we are redirecting to SSL,
so we are already on port 80, why check it?
3º Can be replaced with a Redirect as mentioned above.
So instead of giving out recipes for .htaccess thought
out for an aging era or shared virtualhosting, lets
recommend the ideal virtualhost context recipe first as Yann
proposed earlier:
Define the virtualhost with the names you serve.
<VirtualHost *:80>
</VirtualHost>
There is no guessing here, no unnecessary directives and
it's hard to miss or confuse with other directives and the
context where it resides is crystal clear.
Later on, when things need to be complicated, then I
guess we can use "If" or "mod_rewrite", and recommend it as
needed.