Use traefik to redirect urls

Hello,

This is my first time that I use Traefik and I'm trying to deploy it as forwarding service in a k8s cluster to some external URL. For example when a user try to access the url: http://www.test.com, he will be forwarded to: http://www.google.com

In a YAML file I tried to use the following config.

---
 apiVersion: traefik.containo.us/v1alpha1
 kind: Middleware
 metadata:
   name:  test-redirectregex
 spec:  
   redirectRegex:
         regex: "^http://www.test.com"
         replacement: "http://www.google.com"
         permanent: true

When I apply this config to k8s, I still can't have a forwarding service working properly. What am I missing?

Anyone knows why this is happening?
Thanks!

Hello @Ramzi,

Can you provide the ingress object that you are using this middleware with?

Hello @daniel.tomcej

Thanks for your replay!

Some services are no longer exists in that cluster, and it needs to be forwarded to the new one, so I started removing their ingress object, but it's just a standard one that I'm using it just for testing.

kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: "foo"
  namespace: testing

spec:
  rules:
    - host: test.com
      http:
        paths:
          - path: /logs
            backend:
              serviceName: logs-service
              servicePort: 80

so the idea is jsut forwarding www.TestUrl.com/whaever to www.newTestUrl.com/whaever

Hello @Ramzi,

In this case, you still need to keep the ingress objects that use host, so that the middleware can be used:

(Kubernetes Ingress - Traefik)

This way you can use the annotation to add the middleware to the ingress object.

Please note that your ingress host needs to match the regex in your middleware, or else it won't work!