• Resolved wzshop

    (@wzshop)


    Hi,
    I have old URLs like:
    example.com/webshop/cat/product-name.html
    and like:
    example.com/webshop/cat/subcat/product-name.html

    I want both to be redirected with regex to:
    example.com/product/product-name

    How can I target $1 to only use the productname that comes before the .html?
    I tried:
    Source: /webshop/(.*?)\.html
    Target /product/$1/

    But this also copies the categories to the new url. I can’t just do
    Source: /webshop/.*?/.*?/(.*?)\.html
    Target /product/$1/

    Because not all products are in subcategories.
    So how can I just get the productname that stands before the .html and use that in the target?

    Thanks

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

    (@johnny5)

    Have you tried several redirects, each one targeting the different types of URLs?

    Thread Starter wzshop

    (@wzshop)

    Thanks for getting back to me. Yes that worked, but I was wondering if there is an possibility to automatically get the content that is in between the last slash forward / and .html

    Plugin Author John Godley

    (@johnny5)

    If you can create a regular expression for it, yes.

    You said you can’t use /webshop/.*?/.*?/(.*?)\.html because some dont have subcategories. So use that for ones that do, and then another one for ones that dont.

    Thread Starter wzshop

    (@wzshop)

    Yes but I have to create 2 redirects then. I can’t integrate it into 1 redirect, that redirects both URLs?

    Plugin Author John Godley

    (@johnny5)

    What is wrong with 2 redirects? Regular expressions are complicated and it may not always be possible to do exactly what you want with them.

    You can experiment with https://regex101.com/ if you think there is a way of combining them together.

    https://redirection.me/support/redirect-regular-expressions/

    Thread Starter wzshop

    (@wzshop)

    Okay, thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Redirect .html to new links?’ is closed to new replies.