Laurent Loots
Laurent Loots

Reputation: 145

ERR_TOO_MANY_REDIRECTS when loading images

A few weeks ago, my ISP installed an SSL certficiate on my website. To force all URL's (www and non-www, http and https) to the same URL (https://domain.com/), I used the following .htaccess code:

RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(.*)$ https://domain.com/$1 [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

Now, this works just fine for redirecting URL's correctly. However, sometimes, images won't load correctly and spit out "Failed to load resource: net::ERR_TOO_MANY_REDIRECTS" in Chrome's console. Other browsers fail to load the images too.

A temp fix is to rename the images on my server and try to load them again. The error seems to be occurring at random. The images could have been loading correctly for days and then suddenly refuse being loaded at all.

Anyone have any idea why this could be happening?

Upvotes: 1

Views: 3047

Answers (1)

Kapil
Kapil

Reputation: 1141

Please try to this

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

Also, you can also redirect based on port number, for example:

RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Upvotes: 2

Related Questions