• Resolved xgstq

    (@xgstq)


    Im so stuck on this one, been testing me now for the last 4+ hours so im here to ask for advice ??

    Im trying to redirect two urls as below

    /search-images/nggallery/tags/alton
    /search-images/nggallery/tags/axe-edge

    To the wrdpress search, the structure im after is for the above 2 URLS is

    /?s=alton&post_type=product
    /?s=axe edge&post_type=product

    I initially tried to do both on one redirect, but couldn’t… so decided to try and do one at a time. I’m not sure if this is the right way to do it (advice welcomed)

    The first one was easy enough

    ^/search-images/nggallery/tags/(.[a-zA-Z]*)$

    /?s=$1&post_type=product

    Works a treat, i did it that way so I could then tackle the second type of URL that contains the – between the two words “axe-edge” in this instance and I came up with this

    ^/search-images/nggallery/tags/(.*)-(.*)
    /?s=$1 $2&post_type=product

    Again works great on https://regex101.com/ when testing, but when testing on wordpress site it is removing the – as should and joining the 2 words like this

    /?s=axeedge&post_type=product

    it needs to be

    /?s=axe edge&post_type=product

    Ive tried adding in, %20 (%20) “%20” any ideas would be very much appreciated

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter xgstq

    (@xgstq)

    Found the answer ??

    Just had to use the + symbol between the groups $1 and $2 which worked

    ^/search-images/nggallery/tags/(.*)-(.*)
    /?s=$1+$2&post_type=product

    Thanks for a great plugin

    Plugin Author John Godley

    (@johnny5)

    You could also extend the first regex to include the hyphen:

    ^/search-images/nggallery/tags/(.[a-zA-Z\-]*)$

    Thread Starter xgstq

    (@xgstq)

    Dont think that would work John,

    Because the output couldn’t include the hypen – it needed to convert the hyphen to a plus + somehow to work in wordpress search

    I may be wrong, let me test leaving the hypen in on my site ??

    Thread Starter xgstq

    (@xgstq)

    So it works with the default wordpress search with the hypen, but I was re-directing them to woocommerce search result where the hypen needs to be a plus to work.

    axe-edge = No products were found matching your selection”.
    axe+edge = Got results ??

    Plugin Author John Godley

    (@johnny5)

    You can add a + into the mix:

    ^/search-images/nggallery/tags/(.[a-zA-Z\-\+]*)$

    Thread Starter xgstq

    (@xgstq)

    Yeah still didn’t work John

    I needed the redirect to be as below (note the + between axe edge) so remove the – and replace with +

    /?s=axe+edge&post_type=product

    from the blow url

    /search-images/nggallery/tags/axe-edge

    To make it even more awkward I had urls such as

    /search-images/nggallery/tags/wetton

    Its all good its working a treat at the moment.

    Not used regex’s before until this week, its fair to say that im loving playing on https://regex101.com/ trying all sorts of different stuff ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Stuck on a search redirect format’ is closed to new replies.