# Using redirect\_from while retaining original query string values

**URL:** <https://community.plotly.com/t/using-redirect-from-while-retaining-original-query-string-values/77127>\
**Category:** Dash Python\
**Created:** [July 24, 2023, 11:32pm UTC](https://community.plotly.com/t/using-redirect-from-while-retaining-original-query-string-values/77127 "2023-07-24T23:32:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abennett](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@abennett](https://community.plotly.com/u/abennett)\
**Post date:** [July 24, 2023, 11:32pm UTC](https://community.plotly.com/t/using-redirect-from-while-retaining-original-query-string-values/77127/1 "2023-07-24T23:32:01Z")

</div>

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

```auto
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

```auto
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

```auto
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.
           '''),

])

```

---

<div class="post-metadata">

**Author:** ![abennett](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@abennett](https://community.plotly.com/u/abennett)\
**Post date:** [July 27, 2023, 5:16pm UTC](https://community.plotly.com/t/using-redirect-from-while-retaining-original-query-string-values/77127/2 "2023-07-27T17:16:21Z")

</div>

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.

```auto
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)

```
