routes_in: escape question mark

34 views
Skip to first unread message

nethu...@gmail.com

unread,
Feb 15, 2018, 7:05:32 PM2/15/18
to web2py-users
Hello community. I need to support some legacy URLs in a web2py application. I am able to do this using routes_in and routes_out, but it fails when the URL contains a question mark:

routes_in = [
    ("/index?lang=en", "myapp/default/index_en")
]

The URL is not mapped at all. My attempt to scape it didn't work neither:

routes_in = [
    (r"/index\?lang=en", "myapp/default/index_en")
]

Any suggestions?

Thanks in advance!

Dave S

unread,
Feb 15, 2018, 8:26:56 PM2/15/18
to web2py-users


Aren't those available in request.args[] rather than being left in the URL?  That is, some parsing of the URL is done before this point.

/dps

nethu...@gmail.com

unread,
Feb 16, 2018, 9:07:20 AM2/16/18
to web...@googlegroups.com
I think URL mapping occurs before. However I don't care about the lang value itself, just want to support a legacy URL.

Anthony

unread,
Feb 16, 2018, 11:21:14 AM2/16/18
to web2py-users
Unfortunately, the rewrite system does not match on the query string. Some options are:
  • Use your web server to do the rewrite.
  • Implement WSGI middleware to do the rewrite (or at least rewrite the legacy URLs in a way that the web2py rewrite system can then match them, such as moving the language values from the query string to the URL path). See http://web2py.com/books/default/chapter/29/04/the-core#External-middleware.
  • Add code in a model file to identify these URLs (possibly after a rewrite, which could add an obvious flag to the path) and manually change request.function, request.args, etc. to direct to the appropriate controller. Most of the code and configuration could go in external modules.
  • Direct the different languages to a single function and simply use the value in request.get_vars to determine the appropriate content.
Anthony

nethu...@gmail.com

unread,
Feb 16, 2018, 5:53:39 PM2/16/18
to web2py-users
Thanks Anthony, I'll try with one of those workarounds.
Reply all
Reply to author
Forward
0 new messages