Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Redirecting an old URL to a new one with Flask micro-framework

from flask import Flask, redirect, request

app = Flask(__name__)

redirect_urls = {
    'http://example.com/old/': 'http://example.com/new/',
    ...
}

def redirect_url():
    return redirect(redirect_urls[request.url], 301)

for url in redirect_urls:
    app.add_url_rule(url, url, redirect_url)
 
PREVIOUS NEXT
Tagged: #Redirecting #URL #Flask
ADD COMMENT
Topic
Name
7+7 =