1

I need a simple way to force an https redirect for incoming non-https requests.

In other words, if a request comes in for http://www.example.com or http://example.com I want it to be redirected to https://www.example.com or https://example.com, respectively.

Either of the two options is valid in my scenario - as long as both www and non-www requests get redirected.

I've tried a number of solutions based on a variety of resources, but most of them wind up with me getting an infinite loop - or some kind of error message that redirection has not been properly set-up.

I am using media temple as my host and would love to be able to do this via editing my .htaccess file.

Troy Alford
  • 26,660
  • 10
  • 64
  • 82
  • Check out this page: http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www it has lot of generic solutions for reference. – Grumpy Dec 08 '12 at 01:05
  • You should also consider canonicalising the www vs non-www. – MrWhite Dec 27 '16 at 19:10

1 Answers1

1

Give this a try:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Madbreaks
  • 19,094
  • 7
  • 58
  • 72