Redirect Request

Learn how to use Requestly's Redirect Rule for testing, debugging, and development, with step-by-step guides and use cases.


The Redirect Request Rule in Requestly allows you to seamlessly redirect HTTP requests to a different URL or resource. This is particularly useful for testing, debugging, or even for creating workarounds during development.

Why Use the Redirect Rule?

  • Redirect Production to Local Environment: Map your production scripts or APIs to your local running code and test your local code directly on production sites without deployment. Here's an article with more explanation.

  • Test API version changes: If a new API version is available, you can test backward compatibility by setting up a redirect rule to point all URLs from the old version to the new one. This lets you test the upgrade without modifying your code.

  • Swap Javascript from production to staging/dev environment: Test your dev implementation in tag manager scripts like Adobe DTM, Tealium Tag, and Google Tag Manager Containers before pushing them live on client websites. Learn more here.

How to Configure the Redirect Rule

1

Open HTTP Rules and Create a New Rule

Navigate to the HTTP Rules tab in the web or desktop app. Click on + New Rule and select Redirect Rule from the options.

2

Name and Describe Your Rule

Provide a descriptive name for the rule to keep your setup organized. Optionally, add a brief description explaining its purpose for easier identification later.

3

Define the Source Condition

Define where the rule should be applied by specifying criteria such as URL, Host, or Path. You can choose from options like Regex, Contains, Wildcard, or Equals, or use a Filter for more precise conditions.

For more details on source conditions, read this guide.

Example:

For this example, we are using the Requestly Playground(a demo eCommerce Store) to demonstrate the Redirect Request rule. This gives you a near-live experience of how the rule works. In this case, we are targeting API requests that fetch data for the page, specifically those with query parameters like type.slug:bakery.

  • Condition Type: URL

  • Operator: Contains

  • Value: https://mock.redq.io/api/products?searchJoin=and&with=type%3Bauthor&limit=30&language=en&search=type.slug:bakery%3Bstatus:publish

4

Specify the Redirect Target

Set the target URL to which requests should be redirected. You can use the following options:

  • URL: Redirect to a specific URL.

  • Local File: Redirect to a specific JavaScript file located on your system.

  • Pick From Files / Mock Server: Redirect requests to a mock server or a predefined file from your saved resources.

The local file option is available only in the desktop app.

To redirect requests from one API endpoint to another, set the following:

  • Source URL: https://mock.redq.io/api/products?searchJoin=and&with=type%3Bauthor&limit=30&language=en&search=type.slug:bakery%3Bstatus:publish

  • Redirect Target: https://mock.redq.io/api/products?searchJoin=and&with=type%3Bauthor&limit=30&language=en&search=type.slug:gadget%3Bstatus:publish

In this case, we are changing the query parameter type.slug:bakery in the Source URL to type.slug:gadget in the Redirect Target. This redirects requests for bakery products to a new endpoint for tech products.

You can also import this rule and apply it directly by using this shared list

5

Save and Activate the Rule

Once you are satisfied with your configuration, click Save to store the rule. After saving, make sure to toggle the rule ON to activate it. This will apply the rule and ensure it works as expected.

6

Test the Rule

To verify that the rule is working, click the Test button, enter a relevant URL, and then click Test Rule. You can use the following URL to test the redirection: https://www.requestly-playground.com/?rq-category=redirect.

Initial State

Final State

Updated on