1
# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
# END WordPress

The above .htaccess code does not redirect to HTTPS. Why?

(the IfModule are commented out on purpose to show I haven't missed the rewrite module)

update

When trying it out with http://htaccess.madewithlove.be I received

RewriteCond %{HTTPS} =on    This condition was not met
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]    This rule was not met because one of the conditions was not met
RewriteCond %{REQUEST_FILENAME} !-f This variable is not supported: %{REQUEST_FILENAME}
RewriteCond %{REQUEST_FILENAME} !-d This variable is not supported: %{REQUEST_FILENAME}

My htaccess fu is weak at best so I cannot wrap my head around how

RewriteEngine On

becomes

RewriteCond %{HTTPS} =o

which gets commented

This condition was not met

or that

RewriteCond %{REQUEST_FILENAME} !-d 

gets comment

This variable is not supported: %{REQUEST_FILENAME}

Maybe I am tired. Maybe I am just stupid.

TIA

LosManos
  • 91
  • 1
  • 11
  • 2
    What does not work? What does it do? Did you attempt to debug? Did you remove conditions until it does something? Did you enable the .htaccess feature? Check this: http://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever – ETL Jan 04 '15 at 22:10
  • You're tired. I can tell because you edited your question and replaced your htaccess rules with a completely different and unrelated set of rules. Go get some sleep and try again tomorrow. – Michael Hampton Jan 04 '15 at 22:40

2 Answers2

2

Maybe I am tired. Maybe I am just stupid.

Clearly tired.

I don't remember your exact configuration before your edit but based on this from the test you ran:

RewriteCond %{HTTPS} =on    This condition was not met
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]    This rule was not met because one of the conditions was not met
RewriteCond %{REQUEST_FILENAME} !-f This variable is not supported: %{REQUEST_FILENAME}
RewriteCond %{REQUEST_FILENAME} !-d

you seem to have the following rule and conditions:

RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]

If you look at it after getting some rest, it is clear that it's not what you want.

RewriteCond %{HTTPS} =on

Means execute the rule if the request is httpS. So you want:

RewriteCond %{HTTPS} =off
ETL
  • 6,443
  • 1
  • 26
  • 47
0

With great help of Htaccess tester, another answer on stackexchange, @ETL and @Michael Hampton I ended up with:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Any one of you two can copy my answer and I will mark it as the one (first come first serve) and delete this. Honour those who should.

And to clearify - I was more stupid than tired. Stressed too since my site was down.

Which leads me to a caveat that can be good to know. There is some sort of weird client side caching? that made testing stochastic to say the least. Presently the redirect works on Safari@OSX and Chromium@Win but not on IE11@Win. For me. I guess it will fix itself by tomorrow or when I bother to fire up another machine.
Update: I have played around more. At my customer's office http->https at root level worked but not per article in IE, instead it hung. But in Opera it did. Next day IE worked too. At home my IE did the same somersault but a day faster. Both hung in some sort of wait state.
Why I am writing so much gibberish about failed loads is to hint the next reader that the quick edit-save-reload cycle might not work and to keep >1 browser at hand.

LosManos
  • 91
  • 1
  • 11
  • In other words, my answer correcting your config was correct. Glad you server is back up. Next time... try things out on a dev setup :) – ETL Jan 05 '15 at 21:31