1

The code .htaccess below is working on all browsers, except for IE (I tested it on IE10 and IE11). The goal is to redirect all HTTP traffic to HTTPS, but IE seems to ignore it. Does IE need specific code?

# BEGIN GD-SSL
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_USER_AGENT} ^(.+)$
RewriteCond %{SERVER_NAME} ^domain\.com$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Header add Strict-Transport-Security "max-age=300"
</IfModule>
# END GD-SSL


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

On Firefox, Safari and Chrome if I access any of these:

http://domain.com
http://www.domain.com
https://www.domain.com

I am redirected to https://domain.com

On IE I am not redirected, or I am redirected to HTTP (not HTTPS).

Any ideas as to why?

  • Htaccess has nothing to do with the browser normally. However, this line RewriteCond %{HTTP_USER_AGENT} ^(.+)$ is looking for a user agent name. Not sure what this line is supposed to do, but you can safely remove it to at least test. Make a back-up of your htaccess file before editing it. – closetnoc Feb 5 '15 at 0:11
  • Yes, I know .htaccess has nothing to do with the browser, but it's weird that's only IE that doesn't redirect. I will try removing that line to see what happens. – gdaniel Feb 5 '15 at 0:14
  • That is the only code you have that has anything to do with the browser. It is looking at the agent name and I am not sure why it is there, but I m sure removing it will stop the different behaviors between browsers. – closetnoc Feb 5 '15 at 0:16
  • Most often that's used to target a specific browser, like: RewriteCond %{HTTP_USER_AGENT} .*MSIE.* You can try removing that, however be sure to delete all cache in your browser - IE is notorious for caching issues when testing SSL/HTTPS modifications. – dan Feb 5 '15 at 0:52
  • @dan Thanks! I forgot about browser caching. Excellent point!! I was also jumping around busy today so I did not really sit down and try and determine why ^(.+)$. At first glance, it does not make sense to me at all. What would be the point?? I am communing with Carlos Santana on that very question as we speak. So far he has a lot to say, but nothing on this topic yet. – closetnoc Feb 5 '15 at 2:43
1

In the section marked:

# BEGIN GD-SSL

You can safely delete the line:

RewriteCond %{HTTP_USER_AGENT} ^(.+)$

This is causing your problem though for the life of me I cannot figure out why this line exists. It is a do nothing line really but somehow it did not match the agent name IE was giving. The general rule when doing regular expressions is the match the least first- meaning match only what is necessary. The reason for this is simple. Matching too much always has unintended consequences.

One other thing: And this is important- clear your browser cache just in case. We all have done it. We have fixed a problem, forgot to clear the cache, then think the problem is not solved and try and find another solution. Think Homer Simpson- Dooh!!

  • It's been a while. But just wanted to let you know that removing the user agent worked. – gdaniel May 22 '15 at 14:58
1

Try checking if the port being requested is 80 instead of 443. If 80, redirect to HTTPS.

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]
Header add Strict-Transport-Security "max-age=300"
</IfModule>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.