librelist archives

« back to archive

Permanent redirect

Permanent redirect

From:
Ralf Jung
Date:
2012-05-09 @ 17:16
Hi,

I recently re-wrote my PHP based website in Python using Flask, so I need to 
provide compatibility redirects in order for old links to continue to work.
I collected them all in a separate blueprint, looking like this:

def redirectPermanent(url):
	return redirect(url, 301)

# Blueprint vorbereiten
w = Blueprint('weiterleitungen', __name__)

# Funtion die eine Weiterleitung erstellt
def weiterleitung(quelle, ziel = None):
	if ziel is None: ziel = quelle
	w.add_url_rule('/'+quelle+'.php', ziel, lambda: 
redirectPermanent(url_for('oeffentlich.'+ziel)))

# einfache Weiterleitungen einrichten
weiterleitung('index')
weiterleitung('gpl')
weiterleitung('qt')
weiterleitung('highscore')
...

And this is all essentially working fine. There is just one weirdness: 
Normally, when Firefox gets a permanent redirect (I set up some others in 
other occasions, using PHP or the Redirect option of apache2 - and then of 
course there are these automatically generated redirects to add the trailing / 
to a folder name), it will store this in the cache. Next time I visit the URL, 
it does not even send a query there but remembers the permanent redirect and 
immediately queries the target URL.
For some reason however, the custom redirects set up as above behave 
different. Firefox still queries the original URL, tog et the redirect again.
Does anyone have any idea in which way these redirects are different from the 
others, and what could be done?
If you want to see this in action,
http://mathespiele.ralfj.de/programm.php?id=25
is a redirect which is not cached, while
http://mathespiele.ralfj.de/programm/plotter
(which gets the / added) is cached.

Kind regards,
Ralf