librelist archives

« back to archive

Permanent redirect

Permanent redirect

Ralf Jung
2012-05-09 @ 17:16

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: 

# einfache Weiterleitungen einrichten

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,
is a redirect which is not cached, while
(which gets the / added) is cached.

Kind regards,