<!--

Welcome to ingress-nginx!  For a smooth issue process, try to answer the following questions.
Don't worry if they're not all applicable; just try to include what you can :-).
More info helps better understanding of the issue (needless to say).

If you need to include code snippets or logs, please put them in fenced code
blocks.  If they're super-long, please use the details tag like
<details><summary>super-long log</summary> lots of stuff </details>

-->

<!--

IMPORTANT!!!

Please complete the next sections or the issue will be closed.
This questions are the first thing we need to know to understand the context.

-->

**What happened**:

I am trying set the custom error page for couple of error code . However , 404 is working but somehow 302 error code is not getting parsed . 

Below is the configMap

`---
kind: ConfigMap
apiVersion: v1
metadata:
  name: error-files
data:
  405: |
    <html><head><title>405 Not Allowed</title></head>
    <body>
    <center><h1>405 Not Allowed</h1></center>
    </body></html>
  302: |
    <html><head><title>302 Error Code</title></head>
    <body>
    <center><h1>302 Not Allowed</h1></center>
    </body></html>
  404: |
    <!DOCTYPE html>
    <html>
      <head><title>PAGE NOT FOUND</title></head>
      <body>PAGE NOT FOUND</body>
    </html>
  503: |
    <!DOCTYPE html>
    <html>
      <head><title>CUSTOM SERVICE UNAVAILABLE</title></head>
      <body>CUSTOM SERVICE UNAVAILABLE</body>
    </html>`

_for 404 its getting the same page which I set_ 

`curl -D-  http://172.20.179.13
HTTP/2 404 
date: Mon, 20 May 2024 08:04:23 GMT
content-type: text/html
content-length: 106
x-code: 
x-format: 
x-ingress-name: 
x-namespace: 
x-original-uri: 
x-request-id: b92b8d0124edf2986fab77010321db32
x-service-name: 
x-service-port: 
strict-transport-security: max-age=31536000; includeSubDomains
content-security-policy: default-src 'self' blob: *.infacloudops.net *.cloudtrust.rocks *.infaqa.com *.informaticacloud.com *.informatica.com *.typekit.net *.walkme.com *.pendo.io *.contentful.com; script-src 'self' blob: *.infacloudops.net *.cloudtrust.rocks *.infaqa.com *.informaticacloud.com *.informatica.com *.typekit.net *.walkme.com pendo-io-static.storage.googleapis.com *.storage.googleapis.com *.pendo.io *.contentful.com; style-src 'self' 'unsafe-inline' fonts.googleapis.com icsdownloadsecure.informatica.com *.infacloudops.net *.cloudtrust.rocks *.infaqa.com *.informaticacloud.com *.informatica.com *.typekit.net *.walkme.com *.pendo.io *.contentful.com; font-src 'self' data: blob: fonts.googleapis.com fonts.gstatic.com *.typekit.net *.informaticacloud.com *.infacloudops.net *.cloudtrust.rocks *.infaqa.com *.pendo.io *.informatica.com; img-src 'self' data: *.cloudfront.net *.walkmeusercontent.com *.walkme.com *.pendo.io *.informatica.com *.infaqa.com;
strict-transport-security: max-age=31536000; includeSubDomains
x-content-type-options: nosniff

<!DOCTYPE html>
<html>
  <head><title>PAGE NOT FOUND</title></head>
  <body>PAGE NOT FOUND</body>
</html>`

![image](https://github.com/kubernetes/ingress-nginx/assets/142709637/3accd37a-c8c2-4170-8559-52c9bcec4aef)


**But not for 302** 


`curl -D- http://172.20.179.13/metadata
HTTP/2 302 
date: Mon, 20 May 2024 08:03:28 GMT
content-type: text/html
content-length: 138
location: https://qa-ma.rel.infaqa.com/ma
strict-transport-security: max-age=31536000; includeSubDomains
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff
x-xss-protection: 1; mode=block

<html>
<head><title>302 Found</title></head>
<body>
<center><h1>302 Found</h1></center>
<hr><center>nginx</center>
</body>
</html>`

![image](https://github.com/kubernetes/ingress-nginx/assets/142709637/d12d4914-a64d-4cda-b67f-c872534c50da)

**What you expected to happen**:

all the error codes should pick the custom error pages . 

<!-- What do you think went wrong? -->

Somehow the 302 error code is not parsing . 

**NGINX Ingress controller version** (exec into the pod and run nginx-ingress-controller --version.):
<!--
POD_NAMESPACE=ingress-nginx
POD_NAME=$(kubectl get pods -n $POD_NAMESPACE -l app.kubernetes.io/name=ingress-nginx --field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}')

kubectl exec -it $POD_NAME -n $POD_NAMESPACE -- /nginx-ingress-controller --version  
-->

**Kubernetes version** (use `kubectl version`):

**Environment**:

👍 kubectl version
Client Version: v1.29.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.28.7-eks-b9c9ed7

Environment :

GKE , EKS , AKS
OS : Alpine Linux


- **How was the ingress-nginx-controller installed**:
  - If helm was used then please show output of `helm ls -A | grep -i ingress`
  - If helm was used then please show output of `helm -n <ingresscontrollernamespace> get values <helmreleasename>`
  - If helm was not used, then copy/paste the complete precise command used to install the controller, along with the flags and options used
  - if you have more than one instance of the ingress-nginx-controller installed in the same cluster, please provide details for all the instances

- **Current State of the controller**:
  - `kubectl describe ingressclasses`
  - `kubectl -n <ingresscontrollernamespace> get all -A -o wide`
  - `kubectl -n <ingresscontrollernamespace> describe po <ingresscontrollerpodname>`
  - `kubectl -n <ingresscontrollernamespace> describe svc <ingresscontrollerservicename>`

- **Current state of ingress object, if applicable**:
  - `kubectl -n <appnamespace> get all,ing -o wide`
  - `kubectl -n <appnamespace> describe ing <ingressname>`
  - If applicable, then, your complete and exact curl/grpcurl command (redacted if required) and the reponse to the curl/grpcurl command with the -v flag

- **Others**:
  - Any other related information like ;
    - copy/paste of the snippet (if applicable)
    - `kubectl describe ...` of any custom configmap(s) created and in use
    - Any other related information that may help


**How to reproduce this issue**:

1. Follow the steps mention in  https://kubernetes.github.io/ingress-nginx/examples/customization/custom-errors/ 
2. Add new error code in cofigMap for 302 , 405 etc , something like below
`---
kind: ConfigMap
apiVersion: v1
metadata:
  name: error-files
data:
  405: |
    <html><head><title>405 Not Allowed</title></head>
    <body>
    <center><h1>405 Not Allowed</h1></center>
    </body></html>
  302: |
    <html><head><title>302 Error Code</title></head>
    <body>
    <center><h1>302 Not Allowed</h1></center>
    </body></html>
  404: |
    <!DOCTYPE html>
    <html>
      <head><title>PAGE NOT FOUND</title></head>
      <body>PAGE NOT FOUND</body>
    </html>
  503: |
    <!DOCTYPE html>
    <html>
      <head><title>CUSTOM SERVICE UNAVAILABLE</title></head>
      <body>CUSTOM SERVICE UNAVAILABLE</body>
    </html>`

3. Try to hit the url with curl where we expect it should return 302 as response code . 

error page for response code 302
This is a GitHub Issue
repo:ingress-nginx
owner:kubernetes
Title : error page for response code 302
Issue date:

--- start body ---
<!--

Welcome to ingress-nginx!  For a smooth issue process, try to answer the following questions.
Don't worry if they're not all applicable; just try to include what you can :-).
More info helps better understanding of the issue (needless to say).

If you need to include code snippets or logs, please put them in fenced code
blocks.  If they're super-long, please use the details tag like
<details><summary>super-long log</summary> lots of stuff </details>

-->

<!--

IMPORTANT!!!

Please complete the next sections or the issue will be closed.
This questions are the first thing we need to know to understand the context.

-->

**What happened**:

I am trying set the custom error page for couple of error code . However , 404 is working but somehow 302 error code is not getting parsed . 

Below is the configMap

`---
kind: ConfigMap
apiVersion: v1
metadata:
  name: error-files
data:
  405: |
    <html><head><title>405 Not Allowed</title></head>
    <body>
    <center><h1>405 Not Allowed</h1></center>
    </body></html>
  302: |
    <html><head><title>302 Error Code</title></head>
    <body>
    <center><h1>302 Not Allowed</h1></center>
    </body></html>
  404: |
    <!DOCTYPE html>
    <html>
      <head><title>PAGE NOT FOUND</title></head>
      <body>PAGE NOT FOUND</body>
    </html>
  503: |
    <!DOCTYPE html>
    <html>
      <head><title>CUSTOM SERVICE UNAVAILABLE</title></head>
      <body>CUSTOM SERVICE UNAVAILABLE</body>
    </html>`

_for 404 its getting the same page which I set_ 

`curl -D-  http://172.20.179.13
HTTP/2 404 
date: Mon, 20 May 2024 08:04:23 GMT
content-type: text/html
content-length: 106
x-code: 
x-format: 
x-ingress-name: 
x-namespace: 
x-original-uri: 
x-request-id: b92b8d0124edf2986fab77010321db32
x-service-name: 
x-service-port: 
strict-transport-security: max-age=31536000; includeSubDomains
content-security-policy: default-src 'self' blob: *.infacloudops.net *.cloudtrust.rocks *.infaqa.com *.informaticacloud.com *.informatica.com *.typekit.net *.walkme.com *.pendo.io *.contentful.com; script-src 'self' blob: *.infacloudops.net *.cloudtrust.rocks *.infaqa.com *.informaticacloud.com *.informatica.com *.typekit.net *.walkme.com pendo-io-static.storage.googleapis.com *.storage.googleapis.com *.pendo.io *.contentful.com; style-src 'self' 'unsafe-inline' fonts.googleapis.com icsdownloadsecure.informatica.com *.infacloudops.net *.cloudtrust.rocks *.infaqa.com *.informaticacloud.com *.informatica.com *.typekit.net *.walkme.com *.pendo.io *.contentful.com; font-src 'self' data: blob: fonts.googleapis.com fonts.gstatic.com *.typekit.net *.informaticacloud.com *.infacloudops.net *.cloudtrust.rocks *.infaqa.com *.pendo.io *.informatica.com; img-src 'self' data: *.cloudfront.net *.walkmeusercontent.com *.walkme.com *.pendo.io *.informatica.com *.infaqa.com;
strict-transport-security: max-age=31536000; includeSubDomains
x-content-type-options: nosniff

<!DOCTYPE html>
<html>
  <head><title>PAGE NOT FOUND</title></head>
  <body>PAGE NOT FOUND</body>
</html>`

![image](https://github.com/kubernetes/ingress-nginx/assets/142709637/3accd37a-c8c2-4170-8559-52c9bcec4aef)


**But not for 302** 


`curl -D- http://172.20.179.13/metadata
HTTP/2 302 
date: Mon, 20 May 2024 08:03:28 GMT
content-type: text/html
content-length: 138
location: https://qa-ma.rel.infaqa.com/ma
strict-transport-security: max-age=31536000; includeSubDomains
referrer-policy: strict-origin-when-cross-origin
x-content-type-options: nosniff
x-xss-protection: 1; mode=block

<html>
<head><title>302 Found</title></head>
<body>
<center><h1>302 Found</h1></center>
<hr><center>nginx</center>
</body>
</html>`

![image](https://github.com/kubernetes/ingress-nginx/assets/142709637/d12d4914-a64d-4cda-b67f-c872534c50da)

**What you expected to happen**:

all the error codes should pick the custom error pages . 

<!-- What do you think went wrong? -->

Somehow the 302 error code is not parsing . 

**NGINX Ingress controller version** (exec into the pod and run nginx-ingress-controller --version.):
<!--
POD_NAMESPACE=ingress-nginx
POD_NAME=$(kubectl get pods -n $POD_NAMESPACE -l app.kubernetes.io/name=ingress-nginx --field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}')

kubectl exec -it $POD_NAME -n $POD_NAMESPACE -- /nginx-ingress-controller --version  
-->

**Kubernetes version** (use `kubectl version`):

**Environment**:

👍 kubectl version
Client Version: v1.29.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.28.7-eks-b9c9ed7

Environment :

GKE , EKS , AKS
OS : Alpine Linux


- **How was the ingress-nginx-controller installed**:
  - If helm was used then please show output of `helm ls -A | grep -i ingress`
  - If helm was used then please show output of `helm -n <ingresscontrollernamespace> get values <helmreleasename>`
  - If helm was not used, then copy/paste the complete precise command used to install the controller, along with the flags and options used
  - if you have more than one instance of the ingress-nginx-controller installed in the same cluster, please provide details for all the instances

- **Current State of the controller**:
  - `kubectl describe ingressclasses`
  - `kubectl -n <ingresscontrollernamespace> get all -A -o wide`
  - `kubectl -n <ingresscontrollernamespace> describe po <ingresscontrollerpodname>`
  - `kubectl -n <ingresscontrollernamespace> describe svc <ingresscontrollerservicename>`

- **Current state of ingress object, if applicable**:
  - `kubectl -n <appnamespace> get all,ing -o wide`
  - `kubectl -n <appnamespace> describe ing <ingressname>`
  - If applicable, then, your complete and exact curl/grpcurl command (redacted if required) and the reponse to the curl/grpcurl command with the -v flag

- **Others**:
  - Any other related information like ;
    - copy/paste of the snippet (if applicable)
    - `kubectl describe ...` of any custom configmap(s) created and in use
    - Any other related information that may help


**How to reproduce this issue**:

1. Follow the steps mention in  https://kubernetes.github.io/ingress-nginx/examples/customization/custom-errors/ 
2. Add new error code in cofigMap for 302 , 405 etc , something like below
`---
kind: ConfigMap
apiVersion: v1
metadata:
  name: error-files
data:
  405: |
    <html><head><title>405 Not Allowed</title></head>
    <body>
    <center><h1>405 Not Allowed</h1></center>
    </body></html>
  302: |
    <html><head><title>302 Error Code</title></head>
    <body>
    <center><h1>302 Not Allowed</h1></center>
    </body></html>
  404: |
    <!DOCTYPE html>
    <html>
      <head><title>PAGE NOT FOUND</title></head>
      <body>PAGE NOT FOUND</body>
    </html>
  503: |
    <!DOCTYPE html>
    <html>
      <head><title>CUSTOM SERVICE UNAVAILABLE</title></head>
      <body>CUSTOM SERVICE UNAVAILABLE</body>
    </html>`

3. Try to hit the url with curl where we expect it should return 302 as response code . 

--- end body ---
