title: Nginx Ingress - how to set redirect to external site if there is no matching route?
body: <p>beginner here. I am currently trying to configure Ingress to do two things - if the fibonacci route exists, redirect to the function and pass the parameter, if the route doesn't exist, redirect to another website and attach the input there.</p>
  <p>So, for example, there are two basic scenarios.</p>
  <ol>
  <li><a href="https://xxx.amazonaws.com/fibonacci/10" rel="nofollow noreferrer">https://xxx.amazonaws.com/fibonacci/10</a> -&gt; calls fibonacci function with parameter 10 (that works)</li>
  <li><a href="https://xxx.amazonaws.com/users/jozef" rel="nofollow noreferrer">https://xxx.amazonaws.com/users/jozef</a> -&gt; calls redirect function which redirects to <a href="https://api.github.com/users/jozef" rel="nofollow noreferrer">https://api.github.com/users/jozef</a></li>
  </ol>
  <p>I think the service doing the redirect is written correctly, it looks like this.</p>
  <pre><code>kind: Service
  apiVersion: v1
  metadata:
    name: api-gateway-redirect-service
  spec:
    type: ExternalName
    externalName: api.github.com
    ports:
      - protocol: TCP
        targetPort: 443
        port: 80 # Default port for image
  </code></pre>
  <p>This is how my Ingress looks like. Experimented with default-backend annotation as well as various placement of the default backend, nothing worked. When I try to curl <a href="https://xxx.amazonaws.com/users/jozef" rel="nofollow noreferrer">https://xxx.amazonaws.com/users/jozef</a>, I keep getting 301 message but the location is unchanged. The final output looks like this</p>
  <pre><code>HTTP/1.1 301 Moved Permanently
  Server: openresty/1.15.8.2
  Date: Wed, 13 Nov 2019 15:52:14 GMT
  Content-Length: 0
  Connection: keep-alive
  Location: https://xxx.amazonaws.com/users/jozef
  
  * Connection #0 to host xxx.amazonaws.com left intact
  * Maximum (50) redirects followed
  curl: (47) Maximum (50) redirects followed
  </code></pre>
  <p>Does someone have an idea what am I doing wrong? This is my Ingress. Also, if it helps, we use Kubernetes version 1.14.6. Thanks a million</p>
  <pre><code>apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    name: ingress-nginx
    annotations:
      nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
      nginx.ingress.kubernetes.io/force-ssl-redirect: &quot;false&quot;
      nginx.ingress.kubernetes.io/rewrite-target: /$1
  spec:
    rules:
    - http:
        paths:
          - path: /fibonacci/(.*)
            backend:
              serviceName: fibonacci-k8s-service
              servicePort: 80
          - path: /(.*)
            backend:
              serviceName: api-gateway-redirect-service
              servicePort: 80
  </code></pre>