5

I'm looking to redirect all of:

http://
http://www.
https://www.

to https://

This may have been answered here before, but having gone through the questions that seem relevant they are all not quite what I'm after, and everything I've tried resulted in a redirect loop or not working as hoped.

For example:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

RewriteCond %{HTTPS_HOST} ^example.com
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

Thanks in advance for your help.

PaulSkinner
  • 618
  • 2
  • 9
  • 24

1 Answers1

4

Try:

RewriteCond %{HTTP_HOST} !^energenie4u\.co\.uk$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://energenie4u.co.uk/$1 [R=301,L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • I was very close a couple of times... Thanks so much. – PaulSkinner Oct 02 '12 at 09:33
  • And, goodness help me, if I wanted to do the same, but point them all at the `https://www.` ? – PaulSkinner Oct 02 '12 at 09:44
  • 1
    @PaulSkinner Just change the 2 instances of `energenie4u.co.uk` to `www.energenie4u.co.uk` (minding the `\` escapes) – Jon Lin Oct 02 '12 at 16:25
  • I have done this yet it is not working for me... I prolly did something wrong, how can I troubleshoot? basically for me it still goes to www. although I set it up like how it is here suggested (apache2 ubuntu 14) – ovi Feb 27 '16 at 17:57