Website redirection intermittently work in Firefox but not work at all in IE [duplicate]

After few try an error in website redirection, I manage to perform website redirection but it intermittently works in Firefox but not work at all in IE. I manage to clear all cache and retry in Firefox and it works, but weirdly it does not work after that. I confirmed that I wasn't doing any changes on any files at that time. Did anyone have any idea or face this before? I was sooooo happy that my website finally redirects even I was happy like 2 minutes then it turns up wasn't redirect again. :(( I just need it to redirect when I type http://example.com it redirect to https://www.example.com Below is my redirection in .htaccess file:

RewriteEngine On
#Options +FollowSymLinks
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} ^example\.com$[OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]

Below are my logs:

init rewrite engine with requested uri /
pass through /
[perdir D:/wamp64/www/example/] strip per-dir prefix: D:/wamp64/www/example/ -> 
[perdir D:/wamp64/www/example/] applying pattern '.*' to uri ''
[perdir D:/wamp64/www/example/] RewriteCond: input='off' pattern='!on' => matched
[perdir D:/wamp64/www/example/] RewriteCond: input='www.example.com' pattern='^www\\.example\\.com$' => matched
[perdir D:/wamp64/www/example/] rewrite '' -> 'https://www.example.com/'
[perdir D:/wamp64/www/example/] explicitly forcing redirect with https://www.example.com/
[perdir D:/wamp64/www/example/] escaping https://www.example.com/ for redirect
[perdir D:/wamp64/www/example/] redirect to https://www.example.com/ [REDIRECT/301]

I also found that my website only redirect when I logout from VPN(I need to VPN so that I can connect to the server to fix or get the info that I have done for redirection)

Below is the item that I added in .htaccess file:

    RewriteCond %{HTTPS} !on [OR]
    RewriteCond %{HTTP_HOST} ^example\.com$
    RewriteCond %{HTTP_HOST] ^www\.example\.com$
    RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]

Below are my httpd-vhosts.conf:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "d:/wamp64/www/example"
    <Directory  "d:/wamp64/www/example/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
        Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
    </Directory>
</VirtualHost>

My SSL certificate was configured in httpd-ssl.conf so I point my httpd-vhosts.conf as VirtualHost *:80 Below are my httpd-vhosts.conf:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "d:/wamp64/www/example"
    <Directory  "d:/wamp64/www/example/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
        Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
    </Directory>
</VirtualHost>

Update

Below is what I update in .htaccess by adding [OR]:

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]

And below are the logs that I got:

strip per-dir prefix: D:/wamp64/www/example/ -> 
applying pattern '.*' to uri ''
RewriteCond: input='off' pattern='!on' => matched
rewrite '' -> 'https://www.example.com/'
explicitly forcing redirect with https://www.example.com/
escaping https://www.example.com/ for redirect
redirect to https://www.example.com/ [REDIRECT/301]

I have tried it again in browser but it wasn't redirected. I also try to debug in firefox and host I got is example.com

This is what I got by removing [OR]

RewriteCond %{HTTPS} !on 
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]

Logs:

RewriteCond: input='off' pattern='!on' => matched
RewriteCond: input='www.example.com' pattern='^example\\.com$' => not-matched

Please tell me that my redirection is working cuz I've been work in this for months and getting out of idea now(I hope is not because of my silly mistake...praying!). Please help me and thanks in advance!


I believe you don't actually want this condition:

RewriteCond %{HTTP_HOST} ^www\.example\.com$

Because that would cause an infinite redirect loop to itself, given this is from the .htaccess that applies to the https://www version, too:

RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]

I believe it is a missing space character. Please change this:

RewriteCond %{HTTP_HOST} ^example\.com$[OR]

to this:

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]

Your logfile entries proved that http://www.example.com was successfully rewritten to https://www.example.com/. They didn't prove anything about http://example.com. Adding the space character should fix the latter.


Instead of mod_rewrite you should use something like this in Virtualhost definition:

ServerName  www.example.com
ServerAlias example.com
Redirect permanent / https://www.example.com/

According to Apache httpd documentation.

mod_rewrite should be considered a last resort, when other alternatives are found wanting. Using it when there are simpler alternatives leads to configurations which are confusing, fragile, and hard to maintain.