I'm new to Python and Flask, i need redirect along with arbitrary or full url, its working fine with the blow code.
but if the url has '/#/' in it then its not working, users are bookmarked these urls and i need to redirect to new domain as part of migration.
Example:
user url: http://127.0.0.1:5000/abc1/cba2/#/yyyy/2001
URL to be redirected: http://168.192.0.12:5000/abc1/cba2/#/yyyy/2001
Its not working since the there is # sign, Flask captures url only till # sign [/abc1/cba2/], because of this the redirection fails
How do i resolve this issue?
from flask import Flask, redirect
import json
def create_app():
app = Flask(__name__)
@app.route('/', defaults={'arbitrary': ''}, methods=['GET'])
@app.route('/<path:arbitrary>')
def red(arbitrary):
print (arbitrary)
url_substring = "/yyyy/"
if url_substring in arbitrary:
new_path = 'https://xxxx.com/' + arbitrary
print (new_path)
return redirect(new_path, code=302)
else:
return redirect("https://xxxx.com", code=302)