Guide
How to redirect a URL in Chrome
To make Chrome load a different URL than the one a page asks for, for example your local build in place of the production JavaScript bundle, add a redirect rule. Headerbench has exact-URL and pattern redirects on the free plan, and regex redirects with capture groups in Pro.
Load a production bundle from localhost
- Start your local build, so
http://localhost:8080/main.jsanswers. - In Headerbench, create a profile named Local bundle.
- Open Redirects & blocks and click Add redirect. Leave the match type on Exact URL.
- In Redirect from, paste the production URL, for example
https://app.example.com/assets/main.js. In Redirect to, enterhttp://localhost:8080/main.js. - Open
https://app.example.com, turn the profile on in the popup and allow access when Chrome asks. - Reload. The page now runs your local file. Test a URL with the production URL shows the redirect and its target.
Profile Local bundle
Redirects
Exact URL https://app.example.com/assets/main.js
→ http://localhost:8080/main.js
URL pattern ||app.example.com/assets/vendor.*.js
→ http://localhost:8080/vendor.js
Exact URL, URL pattern or regex
-
Exact URL (free) matches one address, query string included. The
#fragmentis ignored, since it never reaches the network. -
URL pattern (free) uses Chrome’s urlFilter syntax:
||anchors a domain,^ends one,*matches anything. Every match goes to the same target, which suits hashed file names likevendor.3f9a1c.js. -
Regex (Pro) captures parts of the URL and reuses them in the target as
$1,$2. One rule can send a whole CDN path to your machine:^https://cdn\.example\.com/(.*)$tohttp://localhost:3000/$1. Patterns use Chrome’s RE2 syntax, so lookarounds and backreferences are not supported. Adding one starts a 14-day trial with no card; without Pro, regex redirects are kept but paused.
Headerbench refuses a target that matches its own source, since that redirect would loop. Blocks live on the same editor tab: a matching request fails as if the network were down, which is handy for testing how a page copes without a script.
Check that it worked
- In the DevTools Network panel, the original request shows a 307 Internal Redirect followed by the request to localhost.
- Your local server logs the request.
- The popup’s Applied on this tab lists the redirect and the profile.
Chrome DevTools does not always show headers changed by an extension. If the Network panel shows the old value, trust the server’s echo or the popup’s Applied on this tab, which asks Chrome what it actually changed.
Why a redirected script fails to run
The page’s CSP blocks localhost
A script-src policy that lists only the production hosts refuses your local
file. Add the Remove Content Security Policy preset to the same profile, or
a looser policy: see disabling CSP in Chrome.
Subresource Integrity
A <script integrity="sha384-…"> tag rejects any file whose hash differs,
and yours does. A header rule cannot fix that; drop the attribute in your test build or use
a DevTools override (below).
CORS on the local file
Module scripts and tags with a crossorigin attribute are fetched with CORS, so
the response from localhost needs Access-Control-Allow-Origin. If the Console
shows a CORS error for the redirected file, configure your local server to send it, or add a
response row Access-Control-Allow-Origin: * to the profile with a
localhost domain filter.
Local network access
Recent Chrome versions may ask whether a public site may connect to devices on your local network when it loads from localhost. Allow it for the site you are testing.
Nothing redirects
Chrome applies header and redirect rules only when Headerbench has access to the request’s site
and to the page that sends the request, its initiator. A call to
cdn.example.com from an app on app.example.com needs both. Without the
page, Chrome skips the rule without an error. The popup shows a Grant button
when the current page is missing, and Test a URL has a
Sent from page field that checks the pair.
Without an extension
DevTools Local overrides can serve your own copy of a single file: in the Network panel, right-click the request, choose Override content, pick a local folder and edit the file. It lasts while DevTools is open, and you edit a copy rather than your live build. A debugging proxy with a map-remote feature does the same for every app on your machine, at the cost of installing its certificate.