# What happens when traefik redirectregex middleware's regex does not match?

**URL:** <https://community.traefik.io/t/what-happens-when-traefik-redirectregex-middlewares-regex-does-not-match/25864>\
**Category:** Traefik v3 (latest)\
**Tags:** middleware\
**Created:** [January 6, 2025, 1:39pm UTC](https://community.traefik.io/t/what-happens-when-traefik-redirectregex-middlewares-regex-does-not-match/25864 "2025-01-06T13:39:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![YuryHrytsuk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/yuryhrytsuk/32/7717_2.png) [@YuryHrytsuk](https://community.traefik.io/u/YuryHrytsuk)\
**Post date:** [January 6, 2025, 1:40pm UTC](https://community.traefik.io/t/what-happens-when-traefik-redirectregex-middlewares-regex-does-not-match/25864/1 "2025-01-06T13:40:00Z")

</div>

Will the middleware be ignored?

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [January 6, 2025, 3:23pm UTC](https://community.traefik.io/t/what-happens-when-traefik-redirectregex-middlewares-regex-does-not-match/25864/2 "2025-01-06T15:23:44Z")

</div>

If the middleware regex matches, it will redirect, otherwise the processing will continue.

From [simple Traefik example](https://github.com/bluepuma77/traefik-best-practice/tree/main/docker-traefik-dashboard-letsencrypt):

```auto
services:
  whoami:
    image: traefik/whoami:v1.10
    networks:
      - proxy
    labels:
      - traefik.enable=true
      - traefik.http.routers.mywhoami.rule=Host(`whoami.example.com`) || Host(`www.whoami.example.com`)
      - traefik.http.routers.mywhoami.middlewares=mywwwredirect
      - traefik.http.middlewares.mywwwredirect.redirectregex.regex=^https://www\.(.*)
      - traefik.http.middlewares.mywwwredirect.redirectregex.replacement=https://$${1}
      - traefik.http.services.mywhoami.loadbalancer.server.port=80

```

A single `router` will match "www" and non-www. "www" will be redirected, only non-www will continue to target service.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [January 9, 2025, 3:24pm UTC](https://community.traefik.io/t/what-happens-when-traefik-redirectregex-middlewares-regex-does-not-match/25864/3 "2025-01-09T15:24:40Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
