Redirector
Redirector copied to clipboard
Add ability to filter on 'Referer' (and other?) headers
I have a use case where I need to be able to filter on the 'Referer' header. I have a rule where I redirect "www.amazon.com" to "smile.amazon.com". However, I have a higher precedent rule that if I explicitly go to "real.amazon.com" it will go to "www.amazon.com". The problem is, once I click a link on that page it will take me to "smile.amazon.com" on subsequent pages because it now matches the former (lower precedent) rule. I'd like to be able to add an additional condition to the original rule that if the "Referer" matches "www.amazon.com" then it won't redirect.
It may be useful to generalize this and create two fields. The first is a small text field where you type the name of the header you want to match on and the second is the actual regex to match. An additional checkbox to negate the match would cover both including and excluding rules that match the given pattern.
That sounds like it could be useful in very specific cases, but to be honest I feel like the UI is already complicated enough without adding more options and stuff to it.
What about adding it under advanced options? I'm all for making sure the user experience is intuitive and simple. I'm also a big fan of flexibility for advanced and unpredictable use cases. I think both can be achieved by hiding it behinds advanced options.
Maybe there is a simpler general UI. I'll have to think about it some more.
Well, if someone else were to do it in a very unobtrusive way I might accept it, but it's still more code that I'd have to maintain and test on every release etc. I'm not really adding new features to this addon anymore, but I would accept a pull request for it if I felt the UI was good enough.
I think this is also what I want. I'm trying to make a rule that replaces all links directly to https://arxiv.org/pdf/(.*).pdf
with https://arxiv.org/abs/$1
except for when I am already on the abstract page, in which case I obviously want to actually download the pdf when I click the link.
In my specific case, having a checkbox that says "don't replace if the substitution would be the current page" would be enough, but if I read the OP correctly, that would be a cleaner and more general solution.
@black-puppydog Yes, when you click a link on a page the Referer
header is set to the the URL of the page you are currently on. So by implementing this feature, you would then be able to exclude the rule based on the Referer
header just as I want to do and make your download work.
Ok, well that's two votes for doing it. Maybe I could add it as a super hidden feature, letting you put something like "Referer:https://*.foo.com" in the Exclude pattern. Although then you couldn't use a normal exclude pattern. hmmmmm.
Personally, I'd add another field just like the exclude pattern, but applied to the referrer. But then again, I don't know s**t about JS and extension-building, so I'll let the big boys decide how to best do this. :)
Edit: a good text to explain what that field is doing might go a long way to making it less confusing. "This can be used to prevent this filter from being applied when the link comes from a certain page" or something of the sort.
@black-puppydog Yeah, that would be the proper way to do it. I'm just being lazy, I think the feature is kind of technically interesting, but don't wanna write more UI stuff :D
Technically, if you're going to implement it for the special case of the Referer
header and not generic support for all headers then you could just add a checkbox under the exclude pattern with some text like "Apply the exclude pattern to the URL you're coming from". If you want to generic support for any header though then you'll need a free form text field for user's to type the header name they want to apply the pattern to.
Hmmm, what other header would you use for redirection filtering? I can see that it would be generic to allow any header, just wondering what the actual use would be.
The only other standard header I can think of that might be useful in practice is the Cookie
header. An example use case might be someone wanting to do redirection based on the presence of a site's session cookie, indicating whether they're logged in or not.
It's one of those things where it's hard to gauge the value of supporting other headers or not. I have plenty of experiences where I couldn't imagine a use case for something until I had the use case. OTOH, I've had plenty of experiences where I've written code to support a use case that never ended up happening in practice so honestly I'd be happy with whichever way you think is best for now. I don't currently have a use case for another header but I thought I'd throw it out there in case you wanted to create a more general solution.
That... ...makes perfect sense! Cookie might be even more useful than Referer actually. I'm in the middle of rewriting the UI to not use angular.js anymore since Firefox warns about using it in addons, but after that I'll try to add this feature, I've gotten interested in it now :)
Probably won't be out for a month or two though, lots of other projects going on!
Not sure if it'll be of any use for black-puppydog's issue, but my solution for an Amazon Smile Redirect might help @jwarkentin.
Closing this. I don't think it has much general interest and would make the extension even more complicated to use for people.
@Gitoffthelawn hi! Maybe we could reopen that issue at least? Feature is definitely must have. Maybe someday someone will try to develop it
@Kyogre Yes, I think the possible benefits of reopening the issue outweigh any negligible downside of doing so. I'm reopening it now. 👍🏾