V1: rewrite with url parameters

1. Caddy version (caddy version):

Caddy v1.0.3

2. How I run Caddy:

Inside of a Docker container (abiosoft)

a. System environment:

Docker

b. Command:

docker run caddy

c. Service/unit/compose file:

caddy:
    image: abiosoft/caddy:no-stats
    restart: always
    container_name: caddy
    volumes:
      - $HOME/data/backend/static:/static
      - $HOME/data/caddy/Caddyfile:/etc/Caddyfile
      - $HOME/data/caddy/.caddy:/root/.caddy
    ports:
      - 80:80
      - 443:443
    networks:
      - net

d. My complete Caddyfile or JSON config:

# ...
www.domain.com, domain.com {

    # Remove trailing slashes
    rewrite {
        if {path} ends_with /
        r ^/(.*)/$
        to /{1}
    }

    redir 301 {
        if {path} not /
        if {path} ends_with /
        / {rewrite_uri}
    }

    # Redirect the old users to the new admin
    redir /users https://admin.domain.com

    # Special mappings
    redir 301 {
        # REDACTED: Simple redirect for some special paths
    }

    proxy / client:80 {
        transparent
    }

    gzip
}
# ...

3. The problem Iā€™m having:

I am trying to take old URLs still saved in search engines from the old system, and redirect them to the new structure. The idea is to take URLs such as

domain.com/obj/print.php?obj_id=XXXX

and redirect them to:

domain.com/XXXX

4. Error messages and/or full log output:

Not relevant

5. What I already tried:

I cannot find how to capture the id (a 4 digit number) and reuse it to redirect the user to the new page, while also returning a 301.

6. Links to relevant resources:

Caddy v1 is EOL and is no longer supported. Please upgrade to Caddy v2.

You can use the official docker image: Docker Hub

See the upgrade guide:

1 Like

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