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 162 forks source link

Redirects Wayback Machine URLs, despite using an anchor in regex #354

Closed ghost closed 1 year ago

ghost commented 1 year ago

create a rule:

example URL: https://www.reddit.com/ pattern: ^https://(?:.*\.)?reddit.com/(.*) redirect to : https://teddit.net/$1 type: regular expression

attempt to view a saved page matching the pattern on Wayback Machine:
https://web.archive.org/web/20230000000000*/www.reddit.com/r/selfhosted/

The addon redirects to the destination instead. Reproduced on a new Firefox 114.0 profile (Redirector 3.5.3) ; the exported addon config:

{
    "createdBy": "Redirector v3.5.3",
    "createdAt": "2023-06-12",
    "redirects": [
        {
            "description": "Reddit - copy",
            "exampleUrl": "https://www.reddit.com/",
            "exampleResult": "https://teddit.net/",
            "error": null,
            "includePattern": "^https://(?:.*\\.)?reddit.com/(.*)",
            "excludePattern": "",
            "patternDesc": "",
            "redirectUrl": "https://teddit.net/$1",
            "patternType": "R",
            "processMatches": "noProcessing",
            "disabled": false,
            "grouped": false,
            "appliesTo": [
                "main_frame"
            ]
        }
    ]
}
tillcash commented 1 year ago

Give this a try.

{
    "createdBy": "Redirector v3.5.3",
    "createdAt": "2023-07-18T07:49:41.654Z",
    "redirects": [
        {
            "description": "Redirect reddit to teddit",
            "exampleUrl": "https://www.reddit.com/",
            "exampleResult": "https://teddit.net/",
            "error": null,
            "includePattern": "^https?://(?:(?:[^.]+)\\.)?reddit.com/(.*)",
            "excludePattern": "",
            "patternDesc": "",
            "redirectUrl": "https://teddit.net/$1",
            "patternType": "R",
            "processMatches": "noProcessing",
            "disabled": false,
            "grouped": false,
            "appliesTo": [
                "main_frame"
            ]
        }
    ]
}
ghost commented 1 year ago

Give this a try.

{
    "createdBy": "Redirector v3.5.3",
    "createdAt": "2023-07-18T07:49:41.654Z",
    "redirects": [
        {
            "description": "Redirect reddit to teddit",
            "exampleUrl": "https://www.reddit.com/",
            "exampleResult": "https://teddit.net/",
            "error": null,
            "includePattern": "^https?://(?:(?:[^.]+)\\.)?reddit.com/(.*)",
            "excludePattern": "",
            "patternDesc": "",
            "redirectUrl": "https://teddit.net/$1",
            "patternType": "R",
            "processMatches": "noProcessing",
            "disabled": false,
            "grouped": false,
            "appliesTo": [
                "main_frame"
            ]
        }
    ]
}

The rule appears not to match https://old.reddit.com/ and https://www.reddit.com/ (note that loads of other Reddit subdomains are functional and some widely used, most notably np.reddit.com/).

tillcash commented 1 year ago

Above rule will match https://old.reddit.com/ and https://www.reddit.com/. Also you can try this ^(?:https?:\/\/)?(?:(?:[^.]+)\.)?reddit.com\/(.*)

image

ghost commented 1 year ago

@tillcash On a related note, do you know what exactly is wrong with the rule I initially shared?

^https://(?:.*\\.)?reddit.com/(.*)

I'll re-open the issue if this is a Redirector bug. In regex ^ matches the starting position...

tillcash commented 1 year ago

@07416 The regex syntax provided does not meet the specified criteria. To validate the syntax, you can make use of the website https://regex101.com/.