Reputation: 311
Recently my website, which so far is not secure "just http:" fails with multiple problems when it is wrongly linked as https:, which it is not. Unfortunately That will happen regardless of what I want, whenever sites are linked in google, facebook, or just about anywhere now. In the past I successfully solved this problem by adding this JavaScript near the top of my pages...
<script>
// redirect if wrongly linked via https.
if(window.location.href.indexOf("https") >= 0) {
var loc = window.location.href;
var newloc = loc.replace("https:","http:");
window.location = newloc;
}
</script>
Well that no longer works. Is seems that all browsers now have the following behavior: If you link a site vai https://, any attempts to load it via http://, even explicitly typing that on the browser URL line, will fail. the browser will continually change it to https:. So what does this to to my page? It causes it to endlessly reload. Obviously i can remove the script above, but then I may as well shut down the site, because almost nothing will work correctly. No cookies, no graphics, nothing works right. Not even the page icons.
So I also tried the reverse of a .htaccess
file solution, usually used to force https. My version looks like this...
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ http://exampledomain/$1 [R=301,L]
Obviously 'exampledomain' is my domain. I don't know if its doing anything unexpected, but it certainly is not helping.
So what can I do? i realize the long term solution is to become https. That suggestion doesn't help right now. It is a legacy website with over 100 pages. And the way things stand right now, once anyone goes there from an incorrect https: link, they will never get to see any of it. Is there anything i can do for now?
EDIT...
Is it possible the server is forcing this on me? I found this article, and have asked my hosting support if anything can be done. If not, it would seem that the hosting company sold me web space, and then made it impossible for people to visit, if I don't upgrade. Is there any test i can do to see if this policy is being enforced by my hosting company?
https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security
EDIT: I finally got my site back online. I'm not "answering" my own question, because I strongly suspect even now my answer is incomplete. But two things were done:
In my main (document root level), the tech support added these lines. While the lower 3 are similar to something I'd tried (and one of you suggested), without that top line (apparently blocking HSTS), an infinite loop was being generated, when a browser was insisting on https.
Header always unset Strict-Transport-Security
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
But why were MY browsers "insisting" on HTTPS? Tech support had already verified for themselves that a loop condition of infinite redirects was no longer happening, but I still could not reach my pages from home, in either my firefox or chrome browsers, on either my older or newer machine. But oddly, IE and Edge did work, which led me to realize the difference... I don't use those browsers often (except to check compatibility), so the difference was this: Despite suggestions of clearing cache and cookies, apparently none of those options really flush the history. And if an HTTPS was in recent history, the browsers seem to automatically revert to that one. For that i found the answers (at least for those browsers) in the article below. Once history was truly cleared, there was no longer a problem.
https://www.thesslstore.com/blog/clear-hsts-settings-chrome-firefox/
I suspect I haven't seen the last of this problem, and yes... eventually i WILL make the jump to HTTPS. I just don't like needing to do so under forced pressure, because of an internal server policy that changed.
Upvotes: 0
Views: 1644
Reputation: 45958
No... I don't have an SSL certificate.
You need an SSL cert. If you don't have an SSL cert installed that covers the requested hostname then either:
OR,
Is seems that all browsers now have the following behavior: If you link a site vai https://, any attempts to load it via http://, even explicitly typing that on the browser URL line, will fail. the browser will continually change it to https:
That's not true, unless...
OR,
You have previously implemented HSTS. In which case the browser (after initially visiting HTTPS) will always request HTTPS. This is not reversible, until the max-age
time expires after the user has visited your "HTTPS" site. But HSTS is quite a deliberate action - this really shouldn't be something that can be implemented "accidentally". (I would also be surprised that the browser would honour the HSTS header if the SLL cert wasn't entirely valid?!)
Look for a Strict-Transport-Security
HTTP response header when accessing your site over HTTPS. This indicates that HSTS has been "implemented" on your site.
UPDATE:
In my main (document root level), the tech support added these lines....
Header always unset Strict-Transport-Security RewriteEngine On RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
If you are having to explicitly unset
the STS header then it suggests "something else" is already setting it!? This header is not set by default, so it would be a good idea to find out where/what is setting it in the first place. (The web host themselves should never set a header like this.)
Aside: Minor optimisation by changing (.*)
(the RewriteRule
pattern) with just ^
. Since you don't need to match or capture the URL-path, it just needs to be successful (since you are using REQUEST_URI
) in the substitution string.
- But why were MY browsers "insisting" on HTTPS? ... But oddly, IE and Edge did work, which led me to realize the difference... I don't use those browsers often (except to check compatibility), so the difference was this: Despite suggestions of clearing cache and cookies, apparently none of those options really flush the history. And if an HTTPS was in recent history, the browsers seem to automatically revert to that one. .... Once history was truly cleared, there was no longer a problem.
Browser "history" itself would not cause this problem, except that the browser address bar will tend to (sometimes annoyingly) auto-complete to URLs recently visited. But this wouldn't cause a redirect-loop.
So, from this, is the conclusion that it was an HSTS issue? Did your domain appear in the chrome://net-internals/#hsts
list for HSTS-enabled domains? However, this won't solve the problem for any other users who have recently visited your site over HTTPS. They will still be forced to HTTPS until the period determined by the max-age
argument from when they last visited passes.
To clarify:
Upvotes: 1
Reputation: 33
To redirect your website from HTTPS to HTTP, add the following rule in your website’s .htaccess file:
# Redirect HTTPS to HTTP
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Upvotes: 1