Using redirect_from while retaining original query string values

I am writing a multipage dash app which queries a database based on a set of query strings in the url.

Example1: webpage/querydie?lot=X&wfr=Y&die=z

I am going to use this app to replace the current database web interface which was written with .php

Example2: webpage/page/qr/query.php?lot=X&wfr=Y&die=z

Unfortunately the example2 url comes from qr codes on our substrates and would be a nightmare to change to the new url. I would like to use the “redirect_from” argument of the register_page method to redirect from example2 to example1.

What ends up happening is that I am redirected to the page but without the query strings.

Example3: webpage/querydie

Is there a way to carryover the query string from the example2 url? Or even capture the url variables before the redirect?

I have included some sample code to show the issue. In archive.py I tried a couple different methods to try and get it done (commented code) but none gave me the result I was looking for.

app.py

from dash import Dash, html, dcc
import dash

app = Dash(__name__, use_pages=True)

app.layout = html.Div([
	html.H1('Multi-page app with Dash Pages'),

    html.Div(
        [
            html.Div(
                dcc.Link(
                    f"{page['name']} - {page['path']}", href=page["relative_path"]
                )
            )
            for page in dash.page_registry.values()
        ]
    ),

	dash.page_container
])

if __name__ == '__main__':
	app.run(host='localhost', debug=True, port=40)

home.py

import dash
from dash import html, dcc

dash.register_page(__name__, path='/')

layout = html.Div(children=[
   html.H1(children='This is our Home page'),

   html.Div(children='''
       This is our Home page content.
   '''),

])

archive.py

import dash
from dash import html, dcc

dash.register_page(
   __name__,
   path="/archive",
   # path_template="/archive?str1=<str1>&str2=<str2>",
   redirect_from=["/archive-2020"]
   # redirect_from=["/archive-2020", "/archive?str1=<str1>&str2=<str2>"]
)


def layout(str1 = None, str2 = None, **other):
   return html.Div(children=[
           html.H1(children=f"This is our Archive page with {str1} and {str2}"),

           html.Div(children='''
               This is our Archive page content.
           '''),

])

I ended up solving this using flask redirects.

My project is using an apache server run on XAMPP. I’m using mod_wsgi to host the dash app. In my .wsgi file I route the url with querystrings to the new url.

I wanted to go from this
…/web1/web2/webpage.php?str1=foo&str2=bar

to this
…/newweb?str1=foo&str2=bar

Implementing Dash on an apache server hosted through XAMPP was not trivial for me so if anyone has questions on that (which I know is kinda niche) please reach out.

Hope this helps someone.

import sys
from flask import redirect, request

sys.path.insert(0,"C:/project")

from AppDashboard import server as application


@app.route('./web1/web2/webpage.php')
def query_test():
    redir = '/newweb?' + request.query_string.decode()
    return redirect(redir)