Replace Rule is commonly used rule type provided by Requestly. As the word replace indicates, it allows users to replace a string (or matching pattern) with another string in the URL.
Situation: Suppose you are working on a web app which fetches content from your REST API available at http://my-app-server.com/rules. You have cloned the API server, made some changes and running it locally on http://localhost:4000/rules. Now, you want to test your app with the new changes done on API server.
Change the domain in your App code to hit localhost instead of my-app-server. Once your testing is done revert this change.
Use Replace Rule Define a Replace Rule to replace http://my-app-server.comwith http://localhost:4000 in all URLs. No need to change url inside your code. After your testing, just disable the rule. As simple as that.
Chrome Store Feedback
Here is a review listed on Chrome Store about Replace Rule.
Change Query Parameter Values
You can change the values of query parameters present in URL. For example: Changing ?dl-0to ?dl=1 in dropbox URL downloads the file directly without going to the usual preview page. Such a simple use case of Replace Rule.
Fix broken/updated URLs
Often you may find that links to some documentation or blog posts are changed but you have developed a typing habbit of old urls. Well, you can use replace rule to achieve that use case.
Pattern Matching in Replace Rule
With all the use cases mentioned above, we know Replace Rule can be used to replace a string with another string in a Url. Apart from it, Replace Rule can also match a JS Based Regex in the Urls and you can replace them with another string. Please note in case of Regex pattern, you can also use the values of group expressions in your regex and use them in final strings. For Example:
Example 1: Extract domain, pathName and extension for Urls ending with .jpg
$1 is the value of 1st group expression. – DomainName
$2 is the value of 2nd group expression – PathName but not file extension
$3 is the value of 3rd group expression – File extension .jpg in this case