# Regex proxying without redirect

**URL:** <https://community.traefik.io/t/regex-proxying-without-redirect/892>\
**Category:** Traefik v2\
**Created:** [July 15, 2019, 11:47am UTC](https://community.traefik.io/t/regex-proxying-without-redirect/892 "2019-07-15T11:47:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![csamu](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/csamu/32/448_2.png) [@csamu](https://community.traefik.io/u/csamu)\
**Post date:** [July 15, 2019, 11:47am UTC](https://community.traefik.io/t/regex-proxying-without-redirect/892/1 "2019-07-15T11:47:35Z")

</div>

Hello. I am trying to use Traefik to proxy requests transparently from:  
https:// **subdomain**.example.com/ **my/path**  
to  
[https://internet.com/static/](https://internet.com/static/) **subdomain/my/path**

The closest i've found is RedirectRegexp, but that only generates a 302 Location redirect.  
Is it possible to use regex at the service level?

Regards, Christoffer

---

<div class="post-metadata">

**Author:** ![mpl](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@mpl](https://community.traefik.io/u/mpl)\
**Post date:** [August 7, 2019, 4:04pm UTC](https://community.traefik.io/t/regex-proxying-without-redirect/892/2 "2019-08-07T16:04:46Z")

</div>

Hello,

Are you asking how to do that redirect so that it would work for any arbitrary "subdomain" part, i.e. any first subdomain part would dynamically become the second element of the path prefix? If yes, I do not think that is possible to do.

However, if you want to do it for a predefined static subdomain so that e.g [https://foo.example.com/my/path](https://foo.example.com/my/path) forwards to [https://other.domain.com/static/foo/my/path](https://other.domain.com/static/foo/my/path), then I think you can simply do it with a host Rule that matches on [foo.example.com](http://foo.example.com) on the router, and a service (referenced by said router) that has [https://other.domain.com](https://other.domain.com) as one of its servers.

hth,  
Mathieu

---

<div class="post-metadata">

**Author:** ![csamu](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/csamu/32/448_2.png) [@csamu](https://community.traefik.io/u/csamu)\
**Post date:** [August 7, 2019, 8:55pm UTC](https://community.traefik.io/t/regex-proxying-without-redirect/892/3 "2019-08-07T20:55:49Z")

</div>

Hey mpl.  
I wanted to proxy it dynamically with regex, but soon found out that Traefik didn't support that. I solved the problem by placing an Nginx proxy as a Traefik service and letting Nginx handle the proxying instead of Traefik.

Inside Nginx, I get the complete URL by looking in [$http\_x\_forwarded\_host](https://nginx.org/en/docs/http/ngx_http_core_module.html#var_http_), and doing regex on that variable. Then I just [proxy\_pass](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass) to the wanted URL based on the result of the regular expression.

This works nice.

---

<div class="post-metadata">

**Author:** ![Binyang2014](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/binyang2014/32/4523_2.png) [@Binyang2014](https://community.traefik.io/u/Binyang2014)\
**Post date:** [November 25, 2021, 5:59am UTC](https://community.traefik.io/t/regex-proxying-without-redirect/892/4 "2021-11-25T05:59:03Z")

</div>

Hi @mpl. We have the same scenario as csamu. Do we have a plan to implement this feature in Traefik? Otherwise, we need to add additional hop (from traefik to nginx).
