<p>I am struggling with the following issues. I have 2 services running. I am using a wildcard for handling subdomains. See the example conf below:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
    kubernetes.io/ingress.class: nginx
    kubernetes.io/ingress.global-static-ip-name: web-static-ip
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/server-alias: www.foo.bar
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
  name: foo-bar-ingress
  namespace: test
spec:
  rules:
  - host: '*.foo.bar'
    http:
      paths:
      - backend:
          serviceName: legacy-service
          servicePort: 80
        path: /(.*)
        pathType: ImplementationSpecific
  - host: foo.bar
    http:
      paths:
      - backend:
          serviceName: new-service
          servicePort: 8080
        path: /(.*)
        pathType: ImplementationSpecific
</code></pre>
<p>Using the app in the way that abc.foo.bar -&gt; legacy-service and foo.bar -&gt; new-service work perfectly fine. However, when I access the app with www prefix, it gets under the wildcard subdomain path, meaning <a href="http://www.foo.bar" rel="nofollow noreferrer">www.foo.bar</a> goes into legacy-service, which is what I want to avoid. AFAIU this &quot;www&quot; is caught by this asterisk regexp and goes in the wrong way. I would like it go to new-service.</p>
<p>Is there any way I can achieve this with the nginx ingress configuration?</p>

Adam Soliński
<p>Also redirecting requests from <code>www.foo.bar</code> can be achieved by also specifying the hostname. Please note that the order of the hosts does matter as they are translated into the Envoy filter chain. Therefore, the wildcard host should be the last host.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
    kubernetes.io/ingress.class: nginx
    kubernetes.io/ingress.global-static-ip-name: web-static-ip
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/server-alias: www.foo.bar
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
  name: foo-bar-ingress
  namespace: test
spec:
  rules:
  - host: 'foo.bar'
    http:
      paths:
      - backend:
          serviceName: new-service
          servicePort: 8080
        path: /(.*)
        pathType: ImplementationSpecific
  - host: 'www.foo.bar'
    http:
      paths:
      - backend:
          serviceName: new-service
          servicePort: 8080
        path: /(.*)
        pathType: ImplementationSpecific
  - host: '*.foo.bar'
    http:
      paths:
      - backend:
          serviceName: legacy-service
          servicePort: 80
        path: /(.*)
        pathType: ImplementationSpecific
</code></pre>
