1

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?

2 Answers 2

3

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 Redirect and RedirectMatch directives, 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 than RewriteRule. RedirectMatch allows you to include a regular expression in your redirection criteria, providing many of the benefits of using RewriteRule.

A common use for RewriteRule is to redirect an entire class of URLs. For example, all URLs in the /one directory must be redirected to http://one.example.com/, or perhaps all http requests must be redirected to https.

These situations are better handled by the Redirect directive.

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.

1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.