I\'m trying to redirect all insecure HTTP requests on my site (e.g. http://www.example.com
) to HTTPS (https://www.example.com
). I\'m using PHP btw.
Unless you need mod_rewrite for other things, using Apache core IF directive is cleaner & faster:
Redirect permanent / https://yoursite.com/
You can add more conditions to the IF directive, such as ensure a single canonical domain without the www prefix:
Redirect permanent / https://myonetruesite.com/
There's a lot of familiarity inertia in using mod_rewrite for everything, but see if this works for you.
More info: https://httpd.apache.org/docs/2.4/mod/core.html#if
To see it in action (try without www. or https://, or with .net instead of .com): https://nohodental.com/ (a site I'm working on).