ERR_TOO_MANY_REDIRECTS with Page Rules

Hello,

I’ve already asked the similar question, but it doesn’t seem that I solved the problem properly.

My goal:

www.pincoin.co.kr/assets/images/shop/naver/code/*

This URL(static image files) must be served via HTTP.

i.e) http://www.pincoin.co.kr/assets/images/shop/naver/code/1.jpg

and it works for the first time right after I deleted browser caches/cookies.

If I visit http://pincoin.co.kr, https://pincoin.co.kr and browse some pages, it does not work.

When I retrieve the static image file, I see the error message: ERR_TOO_MANY_REDIRECTS

My settings:

  1. DNS

    • A record for www to IP address
  2. Crypto

    • SSL = Full (strict)
    • Always Use HTTPS = Off
    • HTTP Strict Transport Security (HSTS) = Disabled
    • Automatic HTTPS Rewrites = Off
  3. Page Rules

    1. www.pincoin.co.kr/assets/images/shop/naver/code/*
      SSL: Off, Automatic HTTPS Rewrites: Off

    2. http://pincoin.co.kr/
      Forwarding URL: (Status Code: 301 - Permanent Redirect, Url: https://www.pincoin.co.kr/shop/default/)

    3. https://pincoin.co.kr/
      Forwarding URL: (Status Code: 301 - Permanent Redirect, Url: https://www.pincoin.co.kr/)

  4. My nginx settings:

    It doesn’t have any “return redirect” statement. There’re only two server blocks for 80/443 with “www.pincoin.co.kr”.

     server {
         listen 80;
         server_name www.pincoin.co.kr;
         charset utf-8;
    
         root /path/to/repo;
    
         location /assets/ {
             access_log off;
             log_not_found off;
    
             location ~ \.(jpeg|jpg|png|gif) {
                 expires 30d;
                 add_header Cache-Control "public";
             }
    
             location ~ \.(css|js) {
                 expires -1;
                 add_header Cache-Control "public";
             }
         }
     }
    
     server {
         listen 443 ssl;
         server_name www.pincoin.co.kr;
         charset utf-8;
    
         root /path/to/repo;
    
         location /assets/ {
             access_log off;
             log_not_found off;
    
             location ~ \.(jpeg|jpg|png|gif) {
                 expires 30d;
                 add_header Cache-Control "public";
             }
    
             location ~ \.(css|js) {
                 expires -1;
                 add_header Cache-Control "public";
             }
         }
    
         location / {
             include /etc/nginx/uwsgi_params;
             uwsgi_param HTTP_X_FORWARDED_PROTO $scheme;
             uwsgi_pass kr-co-pincoin-www-django;
         }
     }
    

So, do I have to delete page rules “Forwarding URL to www”?

Thank you for your help.

Your first rule looks like it will keep those assets using HTTP. Good.

Your second and third rules only apply to the main page, and nothing else. There are no wildcards.

Rule 2: HTTP visitors to non-www main page are redirected to HTTPS shop/default
Rule 3: HTTPS visitors to main page are redirected to www main page.

These two rules are an odd combination that sounds like you’re trying to accomplish a specific task. Why?

You’re probably going to have to pay for additional Page Rules to accomplish what you’re trying to do.

Hello,

I wanted to redirect the direct access http://pincoin.co.kr or https://pincoin.co.kr into https://www.pincoin.co.kr/shop/default/

Now I merged the RULE2 and RULE3 into this following rule:

pincoin.co.kr/
Forwarding URL: (Status Code: 301 - Permanent Redirect, Url: https://www.pincoin.co.kr/shop/default/)

The reason why I didn’t use wildecard is because I am afraid that it will mess up the RULE1 with infinite redirect loop.

I still have the problem with the next scenario.

  1. Clear browser caches/cookies
  2. http://www.pincoin.co.kr/assets/images/shop/naver/code/7.jpg (OK)
  3. http://pincoin.co.kr (OK - redirected to https://www.pincoin.co.kr/shop/default/)
  4. http://www.pincoin.co.kr/assets/images/shop/naver/code/7.jpg (ERR_TOO_MANY_REDIRECTS :confounded:)

The same URL but not working!

Thank you for your help.

That trip to shop/default set HSTS. You said you’ve disabled it in the Crypto page, but maybe something in the Shop has set it.

I really appreciate your help.

I found out I’ve set up the HSTS on Django, and I was able to fix the problem.

https://docs.djangoproject.com/en/2.1/ref/middleware/#http-strict-transport-security

Thank you again!

1 Like

This topic was automatically closed after 31 days. New replies are no longer allowed.