# HTTP redirects and rewrites Type of document: How-to guide Product: NGINX Gateway Fabric --- Learn how to redirect or rewrite your HTTP traffic using NGINX Gateway Fabric. ## Overview [HTTPRoute](https://gateway-api.sigs.k8s.io/api-types/httproute/) filters can be used to configure HTTP redirects or rewrites. Redirects return HTTP 3XX responses to a client, instructing it to retrieve a different resource. Rewrites modify components of a client request (such as hostname and/or path) before proxying it upstream. In this guide, we will set up the coffee application to demonstrate path URL rewriting, and the tea and soda applications to showcase path-based request redirection. For an introduction to exposing your application, we recommend that you follow the [basic guide](/ngf/traffic-management/basic-routing.md) first. To see an example of a redirect using scheme and port, see the [HTTPS Termination](/ngf/traffic-management/https-termination.md) guide. ## Before you begin - [Install](/ngf/install/) NGINX Gateway Fabric. ## HTTP rewrites and redirects examples We will configure a common gateway for the `URLRewrite` and `RequestRedirect` filter examples mentioned below. ### Deploy the Gateway resource for the applications The [Gateway](https://gateway-api.sigs.k8s.io/api-types/gateway/) resource is typically deployed by the [Cluster Operator](https://gateway-api.sigs.k8s.io/concepts/roles-and-personas/#roles-and-personas_1). This Gateway defines a single listener on port 80. Since no hostname is specified, this listener matches on all hostnames. To deploy the Gateway: ```yaml kubectl apply -f - < ``` **Note:** In a production environment, you should have a DNS record for the external IP address that is exposed, and it should refer to the hostname that the gateway will forward for. ## URLRewrite example This examples demonstrates how to rewrite the traffic URL for a simple coffee application. An HTTPRoute resource is used to define two `URLRewrite` filters that will rewrite requests. You can verify the server responds with the rewritten URL. ### Deploy the coffee application Create the **coffee** application in Kubernetes by copying and pasting the following block into your terminal: ```yaml kubectl apply -f - < 80/TCP 40s ``` ### Configure a path rewrite The following HTTPRoute defines two filters that will rewrite requests such as the following: - `http://cafe.example.com/coffee` to `http://cafe.example.com/beans` - `http://cafe.example.com/coffee/flavors` to `http://cafe.example.com/beans` - `http://cafe.example.com/latte/prices` to `http://cafe.example.com/prices` To create the httproute resource, copy and paste the following into your terminal: ```yaml kubectl apply -f - < 80/TCP 89m service/tea ClusterIP 10.96.151.194 80/TCP 120m ``` ### Configure a path redirect In this section, we'll define two HTTPRoutes for the tea and soda applications to demonstrate different types of request redirection using the `RequestRedirect` filter. 1. The `tea-redirect` route uses the `ReplacePrefixMatch` type for path modification. This configuration matches the prefix of the original path and updates it to a new path, preserving the rest of the original URL structure. It will redirect request as follows: - `http://cafe.example.com/tea` to `http://cafe.example.com/organic` - `http://cafe.example.com/tea/origin` to `http://cafe.example.com/organic/origin` 2. The `soda-redirect` route uses the `ReplaceFullPath` type for path modification. This configuration updates the entire original path to the new location, effectively overwriting it. It will redirect request as follows: - `http://cafe.example.com/soda` to `http://cafe.example.com/flavors` - `http://cafe.example.com/soda/pepsi` to `http://cafe.example.com/flavors` To create the httproute resource, copy and paste the following into your terminal: ```yaml kubectl apply -f - <