I have found two way to redirect http to https with apache. Using Redirect
Redirect / https://mydomain/ Or Rewrite
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://mydomain/$1 [R,L] What are the differences?
The official documentation on When not to use mod_rewrite lists Simple Redirection and also gives your HTTP to HTTPS as an example:
mod_alias provides the
RedirectandRedirectMatchdirectives, which provide a means to redirect one URL to another. This kind of simple redirection of one URL, or a class of URLs, to somewhere else, should be accomplished using these directives rather thanRewriteRule.RedirectMatchallows you to include a regular expression in your redirection criteria, providing many of the benefits of usingRewriteRule.A common use for
RewriteRuleis to redirect an entire class of URLs. For example, all URLs in the/onedirectory must be redirected tohttp://one.example.com/, or perhaps all http requests must be redirected to https.These situations are better handled by the
Redirectdirective.
Your RewriteRule example might be a necessary hack if one only has access to single configuration section that handles both HTTP and HTTPS. That is common when there are .htaccess files involved e.g. on a shared hosting. That is another story; When (not) to use .htaccess files.
They do the same thing. Redirect is simpler, easier to read, and doesn't require mod_rewrite, so it's better to use it unless you need something it can't do.