How to use Rewrite URL tool in Charles Proxy 

Introduction

During local development you might want to rewrite URL for various reasons like switching domains or changing query parameters etc.

“Rewrite URL” comes handy in such cases where you want to overwrite request url without making any changes to your codebase.

Setting up Rewrite URL in Charles Proxy is little complex. You can follow the steps below to configure Rewrite URL with ease.

Browser Extension, that just needs you to fill 1 fields and doesn’t have VPN issues, is also explained later in this post. You can also use that in place of Charles Proxy.

Charles Proxy’s Rewrite Tool: How It Works

Configuring the Rewrite tool in Charles Proxy can be a time-consuming process. It requires navigating through a series of options, which can be difficult to find and set up, especially for users unfamiliar with the tool.

How to Configure Charles Proxy’s Rewrite Tool

  1. Open Charles Proxy and make sure the proxy is turned on and capturing traffic.
  2. Go to the top menu and click on Tools.
  3. In the dropdown, choose Rewrite.
charles proxy response status
  1. This will open the rewrite settings window Here check Enable rewrite box and click Add
Charles proxy rewrite tool settings
  1. Rename the rule to your liking and add a location to which the rule should be applied to
    • Protocol: Here you can select your site’s protocol http or https
    • Host: Here you can enter the host/domain that you want to apply the rule to.
    • Port: You can specify the port on which your site is running.
    • Path: Define the path if you want the rule to apply only to specific paths on the host.
    • Query: Here you can define the query parameters that should be targeted.
Charles proxy's location selection
  1. Now Save the location and click on add in the actions section

Rewrite URL rule action pop up
  • Type: The type tells Charles what to modify. Here we have to select the type of rule we want to use
  • Match: You need to tell Charles when to apply the rule. This is done by matching specific text in the request URL. Here we want to replace the value of google.com with bing.com so we will match the URL google.com.
  • New/Replace: Once a match is found, Charles replaces the text you’ve specified. For example, in this case we want to replace the google.com host, Charles will replace it with the new value we provided.
  1. After saving this you should be able to see the rule and its modifications
  2. Now visit the site you selected and you can see the URL change.
Google redirect to bing

I hope you are able to configure Rewrite URL tool, if you are facing issues in setup of SSL read about SSL setup on Charles Proxy official documentation.

Due to this complicated setup process of Charles Proxy and issues with VPN we, at Requestly, came up with a smart solution. We developed a Browser Extension that can sit inside the browser and use browser’s APIs to intercept and modify your network requests and responses.

Replace String rule in Requestly

Requestly is designed differently so it doesn’t need any SSL configuration and hence works seamlessly with your VPNsRewrite URL is simplified as “Replace String” in Requestly. With just 2 inputs i.e. source URL matching condition, replace value.

There are more advanced rules in Requestly & other features to help you test the working of the rule along with details of how to use this rule are explained below.

replace rule
Overview of Configuration Options

  1. Source Condition: Here you define the condition for the rule to run, you can use inbuilt functions like contains or equal or you can write custom regex or wildcards for pattern matching.
  2. Replace With: Here you have first enter the string you want to replace in the url and then give the value you want to replace the string with. Here we will replace google.com withbing.com.
  3. Filter out Condition: This enables further filtering by defining exceptions or specific rules that exclude certain requests. This makes sure only targeted requests are affected, ignoring the ones that don’t match the conditions.

    Steps to Configure Requestly’s Replace String Rule

    • Install Requestly Extension: Download and install Requestly’s browser extension.
    • Open Requestly Dashboard: Visit app.requestly.io and log in.
    • Click on the Rules tab and then select New Rule.
    • Choose Replace String as the rule type.
    • Enter the URL or URL pattern in the Source Condition field.
    • In the Replace String section, specify the string to replace and the replacement text.
    • Name your rule and click Save.

    After saving the rule, you can test it on your desired network requests. If you’d rather not set it up manually, we’ve created a shared rule for Replace String. You can import it by clicking the button below.

    Or create your own Rule by following the setups below

    Interactive guide

    Check out this interactive and easy explanation of how to create this rule :

    Other Use Cases for Requestly’s Redirect Rule

    Redirect rule in requestly is a powerful tool and can serve many purposes, it can also be used for other usercase like :

    1. Testing Staging vs. Production Environments: Automatically redirect requests from a production URL to a staging environment, allowing you to safely test features before deployment.
    2. A/B Testing Without Server Changes: Use the Redirect Rule to direct traffic to different versions of a webpage or app, making A/B testing faster without needing to deploy code changes.
    3. Avoiding External API Calls: Redirect API requests to mock servers or local environments during development to avoid affecting live data or incurring unnecessary API costs.

    Migrate from Charles proxy

    If you already have a Charles Proxy setup and want to give Requestly a try, You can import these tool settings in Requestly in just few clicks Requestly currently supports following tools that you can import from Charles Proxy:
    • Rewrite
    • Map Local
    • Map Remote
    • No Caching
    • Block lists
    • Block Cookies

    Steps to import

    1. In Charles Proxy, go to the top menu bar and select Tools > Import/Export Settings.
    Charles proxy menu Import Export settings
    1. In the popup window that appears, switch to the Export tab. Under the Tools section, select the tools you want to export and click the Export button at the bottom right.

    Import Export Setting popup
    1. Open the Requestly dashboard. If you don’t have any existing rules, you’ll see an Import settings from Charles Proxy .
    Import from Charles proxy in requeslty dashboard
    1. Upload or drag your exported Charles .xml file into Requestly.

    Import charles proxy settings poip up
    1. Once the import is successful, your Charles Proxy settings will be converted into Requestly rules.

    Conclusion

    I hope you have got a clear understanding of both the Rewrite URL tool in Charles Proxy and how Requestly can achieve the same results with greater ease. While Charles Proxy effectively handles the task, Requestly offers a modern, simple and efficient experience.

    Since Requestly operates directly from your browser and leverages built-in browser APIs, there’s no need for complex SSL configurations, eliminating the VPN issues often encountered with Charles Proxy. Plus, you don’t need to switch between different tools — everything you need is right in your browser.

    Love for Requestly is reflected in its 4.4 ⭐ rating from over 1,200 users on the Chrome Web Store. Requestly is being used by 200K+ developers across the world.

    Happy Debugging!!!

    Expore More

    Share this article:

    Subscribe to our weekly newsletter !

    Join 10k developers and QAs to get weekly updates with Requestly's newsletter.​

    This article was written by:

    Picture of Dinesh Thakur

    Dinesh Thakur

    Dinesh Thakur, fascinated by technology since childhood, has mastered programming through dedication. Whether working solo or in a team, he thrives on challenges, crafting innovative solutions.

    Join 10k developers and get weekly updates with Requestly's newsletter.

    Contents