# Error: rewrite-target annotation value must be a valid regex

- **ID:** `kubernetes/ingress-rewrite-target-missing`
- **Domain:** kubernetes
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

The nginx.ingress.kubernetes.io/rewrite-target annotation is set to an invalid regex pattern or empty string, causing the ingress controller to reject the configuration.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| nginx-ingress-controller 1.8.0 | active | — | — |
| nginx-ingress-controller 1.9.0 | active | — | — |
| ingress-nginx 4.7.0 | active | — | — |

## Workarounds

1. **Use a valid regex with capture groups: 'nginx.ingress.kubernetes.io/rewrite-target: /$2' and path: '/api(/|$)(.*)'** (90% success)
   ```
   Use a valid regex with capture groups: 'nginx.ingress.kubernetes.io/rewrite-target: /$2' and path: '/api(/|$)(.*)'
   ```
2. **Validate regex with online tool before applying, then check with: kubectl describe ingress <ingress-name>** (85% success)
   ```
   Validate regex with online tool before applying, then check with: kubectl describe ingress <ingress-name>
   ```

## Dead Ends

- **Setting rewrite-target to '/' with no capture groups** — 路径不匹配时重写为根路径会导致 404，且不解决正则无效问题 (70% fail)
- **Removing the rewrite-target annotation entirely** — 后端服务可能依赖路径重写，移除会导致路由错误 (60% fail)
- **Using a wildcard '*' in the regex pattern** — 星号不是有效正则，反而会触发相同错误 (95% fail)
