einaregilsson / Redirector

Browser extension (Firefox, Chrome, Opera, Edge) to redirect urls based on regex patterns, like a client side mod_rewrite.
http://einaregilsson.com/redirector/
MIT License
1.54k stars 161 forks source link

[bug] Not redirecting Google results URLs matched by regex #129

Open HatScripts opened 6 years ago

HatScripts commented 6 years ago

None of the following regex-based patterns for Google results are triggering a redirect:

Description: Google - Simplify
Example URL: https://www.google.com.au/search?client=opera&q=test&sourceid=opera&ie=UTF-8&oe=UTF-8
Include pattern: ^(https?://www\.google(?:\.\w+)+/search).*?[?&](q=[^&#$]+).*$
Redirect to: $1?$2
Pattern type: ☐ Wildcard   🗹 Regular Expression
Example result: https://www.google.com.au/search?q=test
Description: Google - Hex colors (Expand shorthand hex colors)
Example URL: https://www.google.com.au/search?client=opera&q=%23fff&sourceid=opera&ie=UTF-8&oe=UTF-8
Include pattern: ^(https?://www\.google(?:\.\w+)+/search.*?[?&]q=%23)([a-f0-9])([a-f0-9])([a-f0-9])((?:&|#|$).*)$
Redirect to: $1$2$2$3$3$4$4$5
Pattern type: ☐ Wildcard   🗹 Regular Expression
Example result: https://www.google.com.au/search?client=opera&q=%23ffffff&sourceid=opera&ie=UTF-8&oe=UTF-8
Description: Google - Currency conversions (Remove '$' from start)
Example URL: https://www.google.com.au/search?client=opera&q=%24100+aud+to+usd&sourceid=opera&ie=UTF-8&oe=UTF-8
Include pattern: ^(https?://www\.google(?:\.\w+)+/search.*?[?&]q=)%24(.+)
Redirect to: $1$2
Pattern type: ☐ Wildcard   🗹 Regular Expression
Example result: https://www.google.com.au/search?client=opera&q=100+aud+to+usd&sourceid=opera&ie=UTF-8&oe=UTF-8

However, simple wildcard-based patterns like the following do seem to work:

Description: Google - wildcard example
Example URL: https://www.google.com.au/search?client=opera&q=test&sourceid=opera&ie=UTF-8&oe=UTF-8
Include pattern: https://www.google.com/*
Redirect to: https://www.google.com/
Pattern type: 🗹 Wildcard   ☐ Regular Expression
Example result: https://www.google.com/

Edit: I'm using the Opera extension, v3.2.

einaregilsson commented 6 years ago

Weird, it seems to work for me on Chrome, Firefox and Opera (although opera annoyingly hides the querystring part of the url by default).

HatScripts commented 6 years ago

This is truly bizarre. I just tested it and it worked when the domain was google.com, google.co.uk, google.com.br, etc., but not google.com.au. It can't be an issue with the regex pattern, because otherwise the Example URL wouldn't match, right?

Could it somehow be because google.com.au is my default search engine in the Opera settings? 2018-09-11 02 34 28 settings_-_opera opera://settings/searchEngines

einaregilsson commented 6 years ago

It's possible that there's some kind of special case where they don't pass that url through the redirection api. Does it matter whether you search from the address bar or from the actual google.com.au page?

HatScripts commented 6 years ago

Does it matter whether you search from the address bar or from the actual google.com.au page?

No, it doesn't work no matter what I try:

Even with all these turned on: 2018-09-11 09 37 37 redirector_-_opera

And even when I change my default search engine, e.g. 2018-09-11 09 30 36

Actually, I just tested it, and it appears that attempting to redirect any URL that is found within those 6 "Default search engines" fails. None of the following simple wildcard redirects will work for me. I was mistaken when I said it's an issue specific to regex redirects.

Description: Google - wildcard example
Example URL: https://www.google.com.au/search?client=opera&q=test&sourceid=opera&ie=UTF-8&oe=UTF-8
Include pattern: https://www.google.com.au/*
Redirect to: https://www.google.com.au/
Pattern type: 🗹 Wildcard   ☐ Regular Expression
Example result: https://www.google.com.au/
Description: DuckDuckGo - wildcard example
Example URL: https://duckduckgo.com/?q=test&t=opera&ia=web
Include pattern: https://duckduckgo.com/*
Redirect to: https://duckduckgo.com/
Pattern type: 🗹 Wildcard   ☐ Regular Expression
Example result: https://duckduckgo.com/
Description: Wikipedia - wildcard example
Example URL: https://en.wikipedia.org/wiki/Special:Search?search=test
Include pattern: https://en.wikipedia.org/wiki/Special:Search*
Redirect to: https://en.wikipedia.org/wiki/Main_Page
Pattern type: 🗹 Wildcard   ☐ Regular Expression
Example result: https://en.wikipedia.org/wiki/Main_Page

Wikipedia tests

These URLs do correctly redirect to the Wikipedia main page:

https://en.wikipedia.org/
https://en.wikipedia.org/wiki/
https://en.wikipedia.org/wiki/Article
https://en.wikipedia.org/w/index.php?search=blahblah&title=Special:Search
https://en.wikipedia.org/wiki/Special:Search
https://en.wikipedia.org/wiki/Special:Search?search=

But these fail:

https://en.wikipedia.org/wiki/Special:Search?search=whydoesnthisredirect
https://en.wikipedia.org/wiki/Special:Search?search=whydoesnthisredirect&searchToken=4ofgo4idb0tyrnq0sp5vx5jgs
https://en.wikipedia.org/wiki/Special:Search?search=asfgf&searchToken=bg1tp1vjwtk38lmiow0xlot7

It should be noted that by design, Special:Search takes you directly to the article if your query is a valid article name, so https://en.wikipedia.org/wiki/Special:Search?search=code -> https://en.wikipedia.org/wiki/Code and thus Redirector will then redirect https://en.wikipedia.org/wiki/Code -> https://en.wikipedia.org/wiki/Main_Page

However, if your query is not a valid article, e.g. https://en.wikipedia.org/wiki/Special:Search?search=xyx it will show search results, and some search token gets appended to the URL: https://en.wikipedia.org/wiki/Special:Search?search=xyx&searchToken=d55zqqne664ltwujujwrd01o9 Redirector then fails to redirect https://en.wikipedia.org/wiki/Special:Search?search=xyx&searchToken=d55zqqne664ltwujujwrd01o9 -> https://en.wikipedia.org/wiki/Main_Page


Edit: Just tested in Chrome and everything works as expected so this definitely seems to be an Opera specific bug.

einaregilsson commented 6 years ago

Ok, thanks for the info. Seems to be some issue around how Opera processes urls that are related to the search engines. I'll try to investigate it better when I have time :)

tiansh commented 6 years ago

Maybe related SO question: webRequest.onBeforeRequest does not fire for certain URLs in Opera 48+ (no answers)

Neustradamus commented 1 year ago

The situation is same at this time?