0
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

I don't understand what !=on means and what REQUEST_URI is.

2 Answers 2

1

In that notation != means NOT EQUAL. That is a combination of comparison =(equal) and boolean operation ! (negate or NOT).

So if rewrite is enable and request does not use HTTPS then replace the request by

https:// (original hostname) / (universal resouce identificator) 

Here URI is the string after the first slash after the hostname. It may include the path in the FS to the static file or some virtual path to the script including parameters passed by GET.

4
  • Will it work if I remove the R=301? What does that do? Commented Jul 27, 2018 at 8:48
  • 1
    Flag [R=code] means that rewriting rule causes the redirection with HTTP code 301 (= "moved permanently") Refer to the official mod_rewrite documentation for further reading: httpd.apache.org/docs/current/mod/mod_rewrite.html Commented Jul 27, 2018 at 8:56
  • 1
    Without the R flag, the server would just attempt to continue processing the modified request URL. In other types of URL modifications this might be possible, but in this particular case the modification calls for switching to the HTTPS protocol, so a redirect is necessary here. Commented Jul 27, 2018 at 9:00
  • @telcoM In this instance, if the R flag was omitted, it would still result in an external (302) redirect. (If you specify an absolute URL as the RewriteRule substitution then Apache will implicitly trigger an external redirect, regardless of whether the R flag is explicity used.) It is the L (last) flag that prevents the continued processing of the URL (in the current pass at least). Commented Jul 27, 2018 at 20:19
1

It redirects http:// to https://

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.