Search code examples
regexelasticsearchhttp-status-code-503broken-links

Regex specific question and search function on my website dealing with broken links


I've been trying to figure out my regex pattern but it doesn't seem to be working for me.

Here's what i'm trying to do:

I have broken links on my website if someone accidentally gets to a page like so: https://example.com/catalogsearch/result/?q= or https://example.com/catalogsearch/result/

So i'm redirecting them back to my homepage. The problem is now the search is just sending everything back to the homepage. So i'm assuming if there is something after the equals it needs to continue the search.. obviously https://example.com/catalogsearch/result/?q=person but currently i can't figure this out..

Here is my regex that i've been messing with for quite sometime now... still seems to be wrong or something else is wrong with my search.

"^/catalogsearch/result((/)|(/\\?)|(/\\?[a-z])|(/\\?[a-z]=))?$"

Please forgive me i'm horrible with regex.


Solution

  • After a lot of discussion, it is concluded that the routes.yaml will consider the url path as a valid route but not the query string part. Hence out of the two examples in the post, you can use

    "/catalogsearch/result": { to: "https://example.com/", prefix: false }
    

    and for other one please change it in nginx config to redirect to homepage or if its not possible then check with magento support on how to incorporate the query string part in routes.yaml file.