How to redirect in frappe a URL that includes parameters?

67 Views Asked by At

In frappe, I am setting the redirections in hooks.py as follows:

website_redirects = [
...
{ "source": "/login", "target": "/entrar" },

However, I had many difficulties to setup a working redirection that included a property. For example, from /login?redirect-to=other-page to /entrar?redirect-to=other-page, the parameter was not passed.

I finally found a solution, but since I did not find any help online and spent several hours to find it, I thought I would post it here to save time to anybody facing a similar problem.

1

There are 1 best solutions below

0
J0ANMM On

The solution eventually was to combine the (barely documented) property "match_with_query_string": True and some regex:

website_redirects = [
...
{ "source": r"/login\?(.*)", "target": r"/entrar?\1", "match_with_query_string": True },
{ "source": "/login", "target": "/entrar" },