Fiddler: Creating an AutoResponse rule to map all calls to one host to another host

20,397

Solution 1

To map from one host to another, don't use AutoResponder. Instead, click Tools > Hosts.

Alternatively, you can click Rules > Customize Rules, scroll to OnBeforeRequest and write a bit of code:

if (oSession.HostnameIs("localhost") && (oSession.port == 24575)) oSession.port = 56832;

Solution 2

This is how I configured Fiddler2 :

I want to redirect all requests from http://server-name/vendor-portal-html/ to http://localhost/vendor-portal-html/ 

My configuration is as follows:

REGEX:.*/vendor-portal-html/(.*)   to    http://127.0.0.1/vendor-portal-html/$1

enter image description here

Thanks to EricLaw for above comment.

Solution 3

Because this was way harder to find than it should have been to use Fiddler to redirect all requests for one to host to another host:

Use the AutoResponder tab to set a rule such that any request matching your old host will redirect to your new host with the path and query string appended.

Match with regex options ix to make it case-insensitive and ignore whitespace. Leave off the n option as it requires explicitly named capture groups.

Capture the path and query string of the request and append it to the redirect response using the variable $1, where the path+query is the first capture group. You can use capture groups $1-$n if your regex has more.

Fiddler will then issue an HTTP 307 redirect response.

Request: regex:^(?ix)http://old.host.com/(.*)$ #Match HTTP host

Response: *redir:http://new.host.com/$1

Redirect old host to new host

Request

GET http://old.host.com/path/to/file.html HTTP/1.1
Host: old.host.com
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive

Response

HTTP/1.1 307 AutoRedir
Content-Length: 0
Location: http://new.host.com/path/to/file.html
Cache-Control: max-age=0, must-revalidate

Solution 4

Mapping requests with Fiddler Autoresponder using Regular Expressions is possible. This can be done with rexexp rules. However this doesn't seem to be documented anywhere.

If you add a rule and use regular expressions within parenthesis, these matches can be used in the desired mapping when using the placeholders ... $n

each number corresponds to the matched regexp in the rule.

Example of Rule: regex:http://server1/(\w*) -> http://server2/

This will result in the following mapping: http://server1/foo.html -> http://server2/foo.html
Share:
20,397
qhawk
Author by

qhawk

Updated on September 28, 2020

Comments

  • qhawk
    qhawk over 3 years

    Example: I want to create one AutoResponse rule that will map all calls to one host to another host, but preserve the urls. Examples

    http://hostname1/foo.html -> http://hostname2/foo.html

    and

    http://hostname1/js/script.js -> http://hostname2/js/script.js

    in one rule. For now, I've accomplished this by creating aN AutoResponse rule for every URL my project calls, but I'm sure there must be a way to right one rule using the right wildcards. I looked at http://www.fiddler2.com/Fiddler2/help/AutoResponder.asp, but I couldn't see how to do it. The wild cards all seem to be around the matching and not the action.

    Full context: I'm developing on a beta platform and Visual Studio is borked in such away that it is sending all the requests to http://localhost:24575 when my project is actually running on http://localhost:56832

  • EricLaw
    EricLaw about 11 years
    Regular expressions are documented in the Fiddler book, in the Help page linked on the AutoResponder tab, and on my blog: blogs.msdn.com/b/fiddler/archive/2012/01/09/…
  • dustEffect
    dustEffect about 11 years
    Nice stuff. I've google it desperately with no success. This is a major feature indeed. Cool blog about Fiddler!
  • Muhammad Umer
    Muhammad Umer over 7 years
    side question is there a way to define request type (say only POST requests)