The Replace String Rule in Requestly allows you to modify the content of HTTP requests and responses, making it easy to test, debug, or apply fixes dynamically without modifying your original codebase. This feature is useful for replacing URLs, headers, or specific content in requests and responses.
Why Use the Replace String Rule?
-
Switch Domains: To test your app with the new changes done on the local server, you can use replace
your-app-server.comwithlocalhostusing Replace String Rule. In this way, you can test your app without having to change any of your code.
Learn more → -
Change Query Parameter Values: You can change the values of query parameters present in a URL.
For example: Changing?dl-0to?dl=1in a Dropbox URL downloads the file directly without going to the usual preview page.
Learn more →
How to Configure the Replace String Rule
1
Open HTTP Rules and Create a New Rule
Navigate to the HTTP Rules tab in the Requestly web or desktop app. Click on 
+ New Rule and select the Replace String option.
2
Name and Describe Your Rule
Provide a descriptive name for your rule to keep things organised. Optionally, add a brief description to explain its purpose for easy identification later.

3
Define the Source Condition
Define the criteria for the rule to be applied, such as URL, Host, or Path. Choose from Regex, Contains, Wildcard, or Equals, or use Advance Filters for more precise conditions.For more detailed guidance, refer to the Source Conditions Guide.
Example:
For this example, we are using the Requestly Playground to demonstrate the
Replace Request rule. This gives you a near-live experience of how the rule works. In this case, we are targeting API requests that fetch product data.To replace the API endpoint to fetch products- Condition Type: URL
- Operator: Contains
-
Value:
https://rest.requestly-playground.com/api/products

4
Replace Part of the URL
In this step, configure the Replace String Rule with the following two sections:
-
Replace: Define the part of the URL you want to replace. This could be the hostname, query value, or any specific part of the URL.
Example:
type.slug:bakery -
With: Specify the value or string that will replace the original part of the URL.
Example:
type.slug:grocery

5
Save and Activate the Rule
Once satisfied with your setup, click Save to store the rule. Don’t forget to toggle it ON to activate it and apply the changes.

6
Test the Rule
To verify the rule works as expected, 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=replace

There are multiple ways to validate if a rule is applied or not, learn more about how to
validate rule execution.- Before
- After


