Why does my .htaccess work for all browsers but Internet Explorer?

Why does my .htaccess work for all browsers but Internet Explorer? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Why does my .htaccess work for all browsers but Internet Explorer? error on your web browser. Problem :


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?


Solution :

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!!



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>

We hope that this article has helped you resolve the htaccess, redirects, internet-explorer error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=