• Resolved patriciava

    (@patriciava)


    Hey,

    so I’m having trouble building a regex string. I’m trying to redirect attachments away from a subfolder like here

    domain.com/en/product/(.*)/?attachment_id=(.*)

    to

    domain.com/produkt/(.*)/?attachment_id=(.*)

    but for a lot of products, so it needs to match the product name and attachment_id

    I’ve been playing around for hours with regex101 but I’m not sure this can be achieved at all.

    ^en\/product\/(.*)\/?attachment_id=(.*)

    to
    /produkt\/(.*)\/?attachment_id=(.*)

    Does anyone have any idea?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author John Godley

    (@johnny5)

    The (.*) – the thing that capture data – only goes in the source. The target uses $1 and $2 – this inserts the captured data.

    You need to escape regular expression characters. If you want to match ? then it needs to be \?

    https://redirection.me/support/redirect-regular-expressions/ has some examples that may help with capturing from the source and inserting into the target.

    Thread Starter patriciava

    (@patriciava)

    Thank you so much John!! That gives me a match in regex101 but still no redirect.
    I’m thinking it has something to do with it being a download link.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Regex for skipping subfolder’ is closed to new replies.