Search code examples
regexfacebookgoogle-chrome-extensionhttp-redirect

In Chrome, eventually using redirect extension with regex, how to redirect all facebook.com URLs to mbasic.facebook.com URLS


Have been searching for days for this, seems like none has had the same idea as mine regarding redirecting Facebook urls from the normal website to the mbasic version site.

My idea is to redirect all "normal" facebook.com urls into mbasic.facebook.com ones at ALL times. Both when i click links on the web, and when i enter an url in the adress bar. Preferably matching facebook.com, www.facebook.com, http(s)://facebook.com, http(s)://www.facebook.com

-- essentially, let them all have a "mbasic." before "facebook" and never see the ordinary facebook site again, but only use the basic version.

.

I've found some redirector extensions in Chrome that uses regex (right now using Requestly), and I think i'm close, but this regex seems invalid:

^((http(s)?:\/\/)?)((www.)?)facebook.com(\/)?.*$

This is what it matches for me at RegExr: https://i.sstatic.net/0HbAE.png . Also tried this one, but is also invalid apparently:

^(http://)*(www.)*((?!mbasic).)*.$

Other times using either regex or wildcard matching, I could get a query for facebook.com to change to mbasic.facebook.com, but whenever I entered, say, an event page (facebook.com/events/ID), it would not redirect, or, the "mbasic" part would be repeated, resulting in a "mbasic.mbasic.facebook.com" redirect.

Also looked at userscripts and changing hostfiles, but I can't seem to find a solution just yet. Hope you can help a bit. Please ask for more information if needed! Thanks in advance.


Solution

  • Since you have already mentioned you are using Requestly, let me try to put up a simple solution using Requestly Redirect Rule and Wildcard operator.

    Try Redirect Rule:

    Source - Url Matches (WildCard) http*://*facebook.com*
    Destination - http$1://mbasic.facebook.com$3
    

    The explanation is very simple

    1. First Match ($1) - 's' if https protocol or '' if http protocol
    2. Second Match ($2) - Subdomain of facebook e.g. www. or any other
    3. Third Match ($3) - Anything after facebook.com

    We are interested in changing $2 value with mbasic and keep $1, $3 as it is and this is what is done in the Destination field.

    Here is a screenshot for reference -

    enter image description here

    I tried it and it looked like working fine.

    Disclaimer - I work at Requestly. For further questions feel free to reach out to us at [email protected] or tweet at @requestlyIO