Redirect too many times on main page only wordpress

Hi, I have a domain.com and domain.com/mag in which the latter is the blog for domain.com.
This is my Caddyfile:

#domain.com/mag, domain.com/mag/* {
#  uri strip_prefix /mag
#  reverse_proxy mag.domain.com {
#    header_up Host mag.domain.com
#  }
#}

domain.com {

    route /mag/* {
        uri strip_prefix /mag
        reverse_proxy mag_site
    }
        
    root * /var/www/mydomain/dist
    # try_files {path} /index.html
    encode gzip
    reverse_proxy nuxt-website:8000
    # file_server
    log {
        output file         access.log
        format single_field common_log
    }
    # tls someone@gmail.com
}

My main doamin.com is working fine with no problem.
I have created a container for domain.com/mag and when I type domain.com/mag in my internet browser, I get redirected you too many times error, but if I enter domain.com/mag/some_article, I see no problem (except some problems like Mixed HTTP HTTPS contents).
Also if I enter domain.com/mag/info.php, it works fine.

This is curl -IL domain.com/mag result:

curl -IL domain.com/mag
HTTP/1.1 308 Permanent Redirect
Connection: close
Location: https://domain.com/mag
Server: Caddy
Date: Wed, 07 Jul 2021 08:43:06 GMT

HTTP/2 404 
accept-ranges: none
content-type: text/html; charset=utf-8
date: Wed, 07 Jul 2021 08:43:09 GMT
server: Caddy
vary: Accept-Encoding
content-length: 49107

What should I do to fix it?

Please fill out the help topic template. What version of Caddy are you using? What’s in your logs? How are you running Caddy? Those questions all matter.

1. Caddy version (caddy version):

v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

Docker container, command is: caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

a. System environment:

Docker

b. Command:

caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

c. Service/unit/compose file:

version: "3"
    
services:
  mag_db:
    build:
      context: .
      dockerfile: Dockerfile_db
    hostname: mag_db
    container_name: mag_db
    image: mag_db:1
    volumes:
      - /home/domain/wp/mag_db/:/var/lib/mysql/
      - /home/domain/wp/conf/mysql/:/etc/mysql/
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 'ROOT'
      MYSQL_DATABASE: 'mag'
      MYSQL_USER: 'mag'
      MYSQL_PASSWORD: 'PASS'
    
  mag_site:
    build:
      context: .
      dockerfile: Dockerfile_site
    hostname: mag_site
    container_name: mag_site
    depends_on:
      - mag_db
    image: mag_site:1
    volumes:
      - /home/domain/wp/mag_site/:/var/www/html
      - /home/domain/wp/conf/apache2/:/etc/apache2/
    restart: always
    environment:
      WORDPRESS_DB_HOST: 'mag_db:3306'
      WORDPRESS_DB_USER: 'mag'
      WORDPRESS_DB_PASSWORD: 'PASS'
      WORDPRESS_DB_NAME: 'mag'
      WORDPRESS_DB_CHARSET: 'utf8'
      WORDPRESS_DB_COLLATE: '

d. My complete Caddyfile or JSON config:

golpino.com {

    route /mag/* {
        uri strip_prefix /mag
        reverse_proxy mag_site
    }

    root * /var/www/mydomain/dist
    # try_files {path} /index.html
    encode gzip
    reverse_proxy nuxt-website:8000
    # file_server
    log {
        output file         access.log
        format single_field common_log
    }
    # tls SOMEONE@gmail.com

3. The problem I’m having:

When I enter golpino.com/mag, I get too many redirects error. But if I type golpino.com/mag/some_article, I see the contents (except some mixed contents HTTPS issues).
Also if I run golpino.com/mag/info.php, I see the phpinfo() result.

curl -v result:

*   Trying IP:80...
* TCP_NODELAY set
* Connected to golpino.com.com (IP) port 80 (#0)
> GET /mag HTTP/1.1
> Host: golpino.com.com
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 308 Permanent Redirect
< Connection: close
< Location: https://golpino.com.com/mag
< Server: Caddy
< Date: Wed, 07 Jul 2021 20:01:25 GMT
< Content-Length: 0
< 
* Closing connection 0

curl -IL result:

HTTP/1.1 308 Permanent Redirect
Connection: close
Location: https://golpino.com/mag
Server: Caddy
Date: Wed, 07 Jul 2021 20:03:21 GMT

HTTP/2 301 
cache-control: no-store, no-cache, must-revalidate
content-type: text/html; charset=UTF-8
date: Wed, 07 Jul 2021 20:03:23 GMT
expires: Thu, 19 Nov 1981 08:52:00 GMT
location: https://golpino.com/mag/
pragma: no-cache
server: Caddy
server: Apache/2.4.38 (Debian)
set-cookie: PHPSESSID=0p7l3t18sk8823an332nadbhkt; path=/
x-powered-by: PHP/7.4.21
x-redirect-by: WordPress

And the second respond is being repeated much.

4. Error messages and/or full log output:

I do not see any error logs.

5. What I already tried:

I only tried changing the index.php file with a simple content like echo hello; and when the content is this, golpino.com/mag works fine.
Also if I try golpino.com/mag/some_article works fine.

6. Links to relevant resources:

Nothing

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