1

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.

Singleton
  • 85
  • 2
  • 5
  • 16
  • `/catalogsearch/result(/$|/\?[a-z]=$)` - Can you try this – rootkonda Aug 28 '20 at 19:55
  • I'll give it a try right now. @rootkonda... i got an error message E: Error parsing configuration files: - routes: Error loading file: while parsing a quoted scalar in ".magento/routes.yaml", line 10, column 11 found unknown escape character in ".magento/routes.yaml", line 10, column 40 – Singleton Aug 28 '20 at 20:51
  • Please escape the special characters where its required. – rootkonda Aug 28 '20 at 20:57
  • oh right... i copy and pasted what you had there... i need to escape it – Singleton Aug 28 '20 at 20:57
  • ^/catalogsearch/result(/$)|(/\?[a-z]=$) < does that look correct @rootkonda – Singleton Aug 28 '20 at 21:02
  • No that looks different from what I mentioned. there is only one capturing group.() and everything comes into that. – rootkonda Aug 28 '20 at 21:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220640/discussion-between-singleton-and-rootkonda). – Singleton Aug 28 '20 at 21:04

1 Answers1

1

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.

rootkonda
  • 1,700
  • 1
  • 6
  • 11