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

23.1k views Asked by At

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

4

There are 4 answers

1
EricLaw On BEST ANSWER

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;
2
dustEffect On

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
0
Nitin Jadhav On

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.

1
nekno On

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