I am creating an add-on to redirect all URLs of a particular domain to a different port on the same domain. For example, redirect example.com/* to example.com:8080/*
This is the code I wrote in background.js:
function redirect(request) {
return {redirectUrl : request.url.replace(/example.com//, “example.com:8080/”)};
}
browser.webRequest.onBeforeRequest.addListener(redirect, {urls : ["://.example.com/*"]}, [“blocking”]);
Now the problem is that redirectUrl is again matched by the pattern specified in the addListener call, so it creates an infinite loop. Apparently, port numbers are disregarded in the pattern matching.
Is this a bug in Firefox, or is there any other way to do what I want?