Rewrite – Redirect URL

Rewriting URLs can be really useful if you need to point your new build to a specific environment i.e. point Prod build at non-Prod env. At a previous company I used this feature to redirect traffic from our Android Test build to our Prod environment.


This tutorial will show you how to use the Rewrite feature to redirect traffic from one website to another. In this example we will redirect users from the NY Times website to BBC News website.

You can also achieve a similar result with the Map Remote feature.

Prerequisites

Go to the NY Times website

Open Chrome and go to https://www.nytimes.com/

Enable SSL Proxying

Return to Charles. Right click the NY Times request and click the “Enable SSL Proxying” option

The Request(s) you want to modify must be decrypted before you can use the Rewrite feature with it

Reload the page on Chrome

Return to Charles. You should now see traffic for http://www.nytimes.com in plain text

Open Rewrite screen

Tools -> Rewrite -> on the Rewrite Settings screen, tick the “Enable Rewrite” checkbox

Configure a Rewrite Location

Add -> Click Add (from the ‘Location’ section) -> Paste https://www.nytimes.com into the “Host” field -> press the “tab” on your keyboard (this will auto populate most of the fields) -> set the “Port” to 443

Setup the Rewrite Rule

Click Add (the centre bottom Add button) to open the Rewrite Rule screen. Configure as follows:

  • Select “URL” from the “Type” dropdown
  • Paste https://www.nytimes.com into the “Value” textfield of the Match section
  • Paste https://www.bbc.com/news into the “Value” textfield of the Match section
  • Click OK to save the Rewrite Rule
  • Click OK to close the Rewrite Settings screen

Reload NYTimes page in Chrome

You should now be redirected to the BBC News site instead

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: