msgbartop
A site for my programming pet projects
msgbarbottom

Redirector

Redirector is a Firefox add-on that lets you create redirects for specific webpages, e.g. always redirect http://bing.com to http://google.com. It was originally done by request for someone on the Mozillazine forums. Include/excludepPatterns can be specified using regular expressions or simple wildcards and the resulting url can use substitutions based on captures from the original url. The add-on can for example be used to redirect a site to its https version, redirect news paper articles to their print versions, redirect pages to use specific proxy servers and more. It’s hosted at the Mozilla Add-ons website, where you can read more about how the addon works and download the latest version. Support requests can be posted here in the comments.

Official Redirector page | Download latest version | Version History | Source code

Reader's Comments

  1. |

    Running on FFX 3.5.7 I get this error when trying to edit an existing redirect:

    uncaught exception: [Exception... "'[JavaScript Error: "Redirect is not defined" {file: "chrome://redirector/content/code/redirect.js" line: 47}]‘ when calling method: [rdIRedirect::clone]” nsresult: “0×80570021 (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)” location: “JS frame :: chrome://redirector/content/code/settings.xul.js :: anonymous :: line 161″ data: yes]

    Line 0

  2. |

    Hi Jason.

    This error has been found before and will be fixed in the next release.

  3. |

    Ok
    http://feeds.hwupgrade.it/rss_hwup.xml
    Thanks for any suggestion

  4. |

    Hi,
    I think it’s a mode to bypass your addon.
    The link is http://feeds.hwupgrade.it/rss_articoli.xml
    Thanks

  5. |

    Ops, double comment, excuse me.

  6. |

    Hi,
    I find a solution using recursive mode but it cause the error “This will cause an endless loop and so the redirect has been disabled to prevent this from happening. You should edit this redirect to fix it”.
    I create a rule for any substitution.
    Example
    http://www.abcdXXefghXXilXXmn.com
    *XX*, $1/$2 > http://www.abcd/efghXXilXXmn.com
    then http://www.abcd/efgh/ilXXmn.com
    and then http://www.abcd/efgh/il/mn.com
    If you add a little option to deactive the error or better to stop the execution before n pass with a selector.
    I hope this solution is more simple to implement.

  7. |

    This script does work really well. One gotta know how to use regexp though.

    Do you think it would be possible to modify it to redirect urls found in javascript code too ?

    Cheers,

    Gabriel

  8. |

    Will there be an update for firefox 3.6 compatibility?

  9. |

    Hi John. It’s already there, it’s just in the sandbox waiting for approval. If you go to https://addons.mozilla.org/en-US/firefox/addons/versions/5064

    you can see version 2.0.2 at the top, that works for 3.6. You probably have to check some “i know this is experimental” checkbox or something like that to be able to download it though.

  10. |

    Any chance you will be updating this excellent add-on for Firefox 3.6+? I would really appreciate it.

  11. |

    I’ll second that. PLEASE release a Firefox 3.6 version of this amazingly useful addon.

  12. |

    See comment above yours, it’s already in the sandbox :)

  13. |

    Cool, works like a charm, thanks so much!!! I really love this add-on, it’s so useful!

  14. |

    For some reason, when using the newest version (the one that works on FF3.6), Redirector causes redirected pages to load in a new window.

    i.e. if a rule kicks in to redirect, it works as expected and redirects to the proper URL. However, it ALSO opens a copy of the redirected URL in a new Firefox window.

    I can certainly send you an export of my export that does this if needed.

  15. |

    @Ryan: I’ve gotten one report about this before, but it only happened when you were opening url’s from outside Firefox, e.g. you clicked a url in MSN Messenger or something like that. Does this happen for you when you are entering urls yourself in Firefox/clicking links inside Firefox? If it does then please send me an example so I can try it out.

    On a more technical note [you can stop reading now :) ] this happens because in Firefox 3.6 it seems that when an url is opened from the outside Firefox opens a new hidden window automatically as well as send the url to any existing Firefox window. I get notification of the new url in two places (both windows) and redirect in both places which causes the new window to become active whereas if I don’t redirect Firefox shuts down the new window before it is ever displayed. Detecting this is pretty hard since the notification I get is just a url and I need to figure out if that url is also being/has been loaded in a different window.
    If any addon developer have any ideas about this then please let me know, because so far I’ve got nothing…

  16. |

    #einar You are absolutely right. Only when I make a desktop shortcut (or use an external application, as my case is) does the second window open.

    Both clicking a bookmark/link and typing in the URL manually behave perfectly.

    I hope you are able to find a way to work around this issue. Currently my biggest reason for using Redirector is to change URLs that are hard-coded into external applications.

    As for a possible solution, couldn’t you wait until the server returns a header before redirecting? I assume that is when Firefox shuts down the second process (the second hidden window).

    Granted, you would lose some time, since you have to wait for the server to respond, but it wouldn’t be much time assuming the server headers aren’t abnormally full.

  17. |

    @Ryan: Unfortunately I can’t wait for a header before redirecting. Redirector is implemented as a content policy in Firefox, which means that the request to the original url is blocked before it ever leaves the browser. This is a feature, a feature that a lot of people care about.

    As far as I can tell (and I haven’t spent much time on this yet) the new window remains activated because I reject the url being loaded and start loading a new one. If I accept the url being loaded then the window is never shown. I could probably come up with some heuristic, e.g. this is a new window with only one tab, I should probably check if there exists another window where the same url is being loaded etc. But another problem here is that I really want to do as little as possible during the checking of an url, since this is code that runs for every single loaded url in your browser and so could have some performance implications if I start looking for windows or waiting for some stuff.

    I’ll ask around about it on some Firefox forums, this behaviour clearly wasn’t there in 3.5, so maybe someone can tell me what happened.

  18. |

    Hi Einar,
    I need redirector works for my problem so I open the js file and I add some function and all works with Unescape Matches checked. Then I wanted add a second Unescape Matches option but I can’t manage the .xpt file and my works stop. If you mail me I send you my mod so you can add to official softwar if you want.
    I add the option to UI changing unascapeMatches in unascapeMatchesA and unascapeMatches and I modified all the js file with this var. I hope you want help me.
    Bye

  19. |

    Hi Einar,

    Thanks for a very nice add on!

    I have some small problems though and I am not sure if it’s a bug or just a missconfiguration from my side.. Maybe you can help me sort it out?

    I would like to redirect everything from a website to another e.g.

    http://www3.interscience.wiley.com/*

    to

    http://www3.interscience.wiley.mylibrary.com/*

    to use my library’s proxy to access articles.

    (include: first line above, redirect to: second row above, everything else blank (use wildcards))

    If I browse the website from within it works great, but when I try to access anything (e.g. http://www3.interscience.wiley.com/journal/123218273/abstract) from outside the browser e.g. google, I just end up on: http://www3.interscience.wiley.mylibrary.com/*

    Am I missing something?

  20. |

    @Oscar: Are you sure these are the patterns you’re using? The redirect to should at least not be

    http://www3.interscience.wiley.mylibrary.com/*

    but should be

    http://www3.interscience.wiley.mylibrary.com/$1

    instead. (You use $n in the redirect-to url to indicate which * in the include pattern to fill in from, first star => $1, second star => $2.

  21. |

    Yes, now it works! Thanks a lot! I’ve been scratching my head for a long time about this one.. I guess it’s not too easy if you don’t know what you’re doing.. :P

  22. |

    Does this addon only redirect the URL in the browser window, or will it redirect any requested URL? eg JS includes, XHR etc etc?

    I am only asking because I want to redirect a JS include from one server to my localhost to debug something… and its not redirecting.

  23. |

    @Peter: This only redirects documents, that is the url in the browser window, or in frames/iframes.

  24. |

    Hey einar – thanks for a great app.
    I would love to redirect all addresses from
    imdb.com to pro.imdb.com
    Like http://www.imdb.com/title/tt1139797/
    to: http://pro.imdb.com/title/tt1139797/
    Thanks

  25. |

    Hello and thank you for the addition of manual sorting and thank you for adding functions to test endless loop !

    Redirector :: Add-ons for Firefox Version 2.0.2 — January 18, 2010 — 84 KB

    The 2 tests endless loop could they be displayed with the button “Test Pattern” (result of 2 tests always displayed) and when i try to validate the changes with “OK” (result of 2 tests displayed in case Error detected) and not separately (1 test with the button “Test Pattern” and the other test with the “OK”) ?

    Can you please add a “+” and “-” ( “-” gray with 1 line, respectively) in front or behind the lines “Include Pattern” and “Exclude pattern” to add or remove a line respectively ? Especially handy and easy to use with “Wilcard” = “*” (rather simple to understand and use).

    Can you please add a sign like “╫▓╫” on the line almost completely right between 2 rules to tie them together with an option to apply all rules tied together ? Leave an empty frame on all lines = style mortise and tenon with locking, operated by clicking or dragging the fasteners with the mouse.

    Thank you very much ! I’m french, sorry for my english (translate with the help of G00GL£).

  26. |

    Any chance of porting this to Chrome / Chromium please?

    This extension is a blessing for craigslist, but I rarely use Firefox anymore.

  27. |

    @Fred: Sorry, I doubt all these changes will make it into Redirector. For more complex patterns that should be able to match one or more patterns you’ll have to use regular expressions and use their capabilities to match one or more things (the | operator). You’re right though that the test pattern should also do the recursive test, I’ll look at that in a future version.

    @Amiga: I don’t have any idea about the state of Chrome extensions or what they are capable of so it’s highly unlikely that this will be ported anytime soon. But what I will do is look at Chrome and try to evaluate how much time and effort it would be to port.

  28. |

    einar – I like it, but wish it could be used to rewrite _every_ request made on behalf of the browser. I’m not even sure if that’s possible with the plugin interface.

    The specific problem I’m trying to address is to force Flash loads of my .swf files to debug versions of the same. Since my .swfs are loaded via a third party one, I’m unable to control that end.

    ie http://blah.me.com/flash/SomeSwf.swf to http://blah.me.com/flash.debug/SomeSwf.swf

  29. |

    I`ve found bug in latest version (2.0.1) – the first item in the list of redirects is not editable, only second or next one.

  30. |

    One useful option would be to allow us to have the Example URL / Include Pattern page actually load, but define a timed interval before the redirect page loads. This would be very useful when you have a form submission page that requires the confirmation page to load in order for the form submission data to post.

    (In our case, we have a Ratepoint subscription page which we’re using in a kiosk-type manner in a retail setting, and we need to have the confirmation page redirect after a set interval, back to the subscription page. With the Redirector addon, the immediate redirect from the confirmation page back to the signup page causes the form data to not be posted.)

    Steve

  31. |

    Works perfectly for my needs, I am already loving it.

    Regex pattern: http://([a-z]+)\.(wikipedia|wiktionary|wikimedia|wikisource|wikiquote|wikibooks|wikinews|wikiversity)\.org(.*)$
    Replace with: https://secure.wikimedia.org/$2/$1$3

    SSL powered kiwis :D

  32. |

    I’ve done preliminary tests (install, configuring one redirect and testing it) worked well. I only got a 404 because the application was not yet correctly deployed but that is another issue.

    Thanks for the addon, it’ll be of great help to the team I’m part of.

  33. |

    Hey, thanks again for this marvellous add-on. Quick question: I’m trying to get all of New York Times’ articles to redirect to their print version, but there seems to be a loop which Redirector does not detect. I’m pretty sure I’m doing it right, but…

    example url: http://www.nytimes.com/2010/04/19/technology/19facebook.html (should lead to http://www.nytimes.com/2010/04/19/technology/19facebook.html?pagewanted=print)
    include pattern: http://www.nytimes.com/(.*).html$
    exclude pattern: pagewanted=print
    redirect to: http://www.nytimes.com/$1.html?pagewanted=print

    any ideas…? thanks!

  34. |

    @Leo: Hmm, this was a fairly interesting problem. nytimes.com doesn’t want you to link directly to their print page, only to access it from the ‘Print’ link on the main page. So, if you enter the print page directly into the browser nytimes.com will itself redirect you to the normal version. So nytimes.com and redirector were each redirecting the other again and again.

    I don’t know how technical you are (a bit I guess since you used a regular expression), but if you know something about how the web works they were simply checking the referer header to see if you were coming from the main page or not. You can fix this yourself if you’re up for some hacking on the Redirector code. Otherwise I might add an option for this in a future release but that’s a long way away.

    Anyway, if you want to fix this yourself, here’s what you do:

    1. Find the file redirector.prototype.js, it should be in your Mozilla profile folder under \extensions\redirector@einaregilsson.com\chrome\content\code.

    2. Open in text editor. Find the line that goes:
    aContext.loadURI(redirectUrl, requestOrigin, null);

    Right above it, paste in these lines:

    if (redirectUrl.substr(0,22) == ‘http://www.nytimes.com’) {
    requestOrigin = contentLocation;
    }

    Save and restart your browser. Your original redirect should work now.

    Enjoy :)

  35. |

    @einar

    Aha!!! Well that’s brilliant (you, not NYTimes)! Thanks again. I opted for installing the RefControl add-on in Firefox instead, setting it to forge any site’s referrer requests from now on. And it works great.

    Thanks again so very much. I swear I’ll make a donation as soon as I get a job!

    Take care and have a nice day.

    Leo

    PS: For anyone interested in the regular redirect I mentioned earlier, the ‘include pattern’ should actually be ‘http://www.nytimes.com/(.*).html*.?’ (sometimes links add a source at the end of the string, and using the end of line I wrote earlier voids the redirect). The ‘exclude pattern’ and ‘redirect to’ are still fine.
    PPS: We should start building a repository for Redirector, like the one Greasemonkey has in userscripts.org. Just saying…

  36. |

    Hi. I’m having troubles with external links. If I recall correctly it changed with 3.6.
    On a new profile I don’t get this error. Seems related though. Maybe something in about:config.
    +Redirector debug
    http://paste2.org/p/791516

    What happens is, I get two windows.

  37. |

    how to redirect from:
    http://www.facebook.com
    to:
    https://www.facebook.com

  38. |

    Greetings,

    Thanks for a great add-on. I have a bug report!

    The import/export functionality doesn’t work for me. The files are neither read in nor written out. I have a syntactically correct .rdx and importing didn’t work; I added a rule and tried to export it, but nothing was written.

    I’m running Firefox 3.6.3 on Mac OS X 10.6.3.

    Suggestions?

  39. |

    @Jubal: I’ve gotten reports before that import/export doesn’t work on Mac. Unfortunately I don’t have a Mac to test on so it’s hard for me to fix. Can you give me some more info:

    1. When you try to import/export, do you see the file picker dialog, or does just nothing happen when you press the import/export buttons?
    2. After you’ve tried it, can you go to Tools-> Error Console and see if there are any errors there and send them to me?

    Then maybe I can figure out what the problem is. I’m just using the Firefox file API’s which should work on all platforms, but apparently they don’t :(

  40. |

    Hi again, Einar…

    I’m having the same problem as Ralph: when I click on a link outside Firefox (e.g. clicking on a link in a Word document) that matches one of my patterns, Redirector does recognize it and open the corresponding redirected address in Firefox. However, it does so by opening the link both in my current Firefox window, and in an entirely new one.

    Any ideas…? Thanks in advance.

  41. |

    Whew. Now we’re two Leo ^^.
    I had a brief encounter with einar over email.
    Went unsolved.. :(

    >>I don’t think that’s redirector that’s doing that. When I open that link (and I have no redirects set up for it) the site itself send me a 301 redirect header which changes the url.

    best regards,
    Einar

    >>>I was aware of this (maybe not that the redirect was the culprit). I just thought
    you would be able to work around this.. ?
    I would reinstall 3.5, but I don’t want to mess around. I’m pretty sure something
    has changed with the .6 update, unfortunately.

    regards

  42. |

    @Ralph, Leo: That error is caused by some changes in FF 3.6. Unfortunately I haven’t been able to figure out any good solution for it :/

  43. |

    Oh, ok. What I thought.. :(
    Well, since you didn’t answer my email I supposed you simply ignored it.
    Thanks for responding. :)

  44. |

    Please update it for Firefox 4.0.

  45. |

    Hi Einar, this plugin looks great! Any chance it could be made to work with post requests?
    Bugzilla uses absolute URLs, which doesn’t work too well as the group I work with access it via multiple IPs.

    Either way, thanks for the great plugin :-)

  46. |

    @Thor: I’ll try to update for 4.0 sometime soon.

    @rob: Sorry, post requests will not be supported. Redirector is implemented as a content policy (nsIContentPolicy) and works by blocking one request and then just issuing another one right after. With post requests I’d have to hook into the request body somehow and do all sorts of things that could be tricky to implement. Maybe someday, but not anytime soon.

  47. |

    Hello again,
    I’ll try to ask this question again:
    Is it possible to redirect all *.imdb.com links to pro.imdb.com ?
    Like http://www.imdb.com/title/tt1139797/
    to: http://pro.imdb.com/title/tt1139797/
    Thanks

  48. |

    @Plougstroup: Sorry, I haven’t been watching the comments closely for a while. Try this out:

    Include: http://www.imdb.com/*
    Exclude: http://pro.imdb.com/*
    Redirect to: http://pro.imdb.com/$1
    Set pattern type to ‘Wildcard’

    That should work. Let me know if you run into problems with it :)

  49. |

    Yes sir !
    Thank you so much einar :-)
    It works perfectly.

  50. |

    Hi,

    Great add-on! I’d love to be able to rewrite all requests made by the website instead of just the location bar URL. I think this would be extremely useful for web developers who want to rewrite URLs such as images to another location.

    Any chance of this feature being implemented?

    Thanks!

Leave a Comment