I would like to create a flexible redirect rule that reorders parts of the url around. Here is the code I am using:
const allResourceTypes = ["main_frame", "sub_frame", "stylesheet", "script", "image", "font", "object", "xmlhttprequest", "ping", "csp_report", "media", "websocket", "other"];
chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [1],
addRules: [
{
id: 1,
action: {
type: "redirect",
redirect: {
// regexSubstitution: "http://localhost:8080/c/b/a"
regexSubstitution: "http://localhost:8080/\3/\2/\1"
}
},
condition: {
resourceTypes: allResourceTypes,
// regexFilter: "http://localhost:8080/a/b/c"
regexFilter: "http://localhost:8080/(.*)/(.*)/(.*)"
}
}
]
})
When I browse to http://localhost:8080/a/b/c I get a “too many redirects” error, obviously because the rule is matching itself over and over. Is there any way to prevent this? It should just redirect me to http://localhost:8080/c/b/a and stop.